我使用以下jquery代码调用www.example.com核心控制器中的POST方法Asp.net
$.ajax({
url: '@Url.Action("GetItemsForRelease", "PointOfSales")',
data: { requestModel: TFObj },
type: 'POST',
contentType: "application/json; charset=utf-8",
dataType: "html",
success: function (responsedata) {
$("#releaseItemsPush").html(responsedata);
},
error: function (error) {
console.log(error);
}
});
但以下控制器操作显示空对象
[HttpPost]
public ActionResult GetItemsForRelease(RequestModel requestModel)
{
return PartialView("_partialReleaseItem", requestModel);
}
1条答案
按热度按时间krcsximq1#
以下控制器操作显示空对象
那么,根据您共享的代码片段
contentType: "application/json; charset=utf-8
导致您的控制器上的空数据,这是因为您将dataType
定义为html
,但contentType: "application/json; charset=utf-8",
。当我们发送html
作为dataType
,它将视为text
在控制器中,因此发布的数据已丢失,由于不匹配的数据类型。假设您有以下模型:
型号:
AJAX :
控制器:
输出:
contentType
即可解决您的空数据。