我遇到了通过Ajax将表单数据和DataSourceRequest发布到我的控制器方法的问题。我能够单独传递每个对象,但是当我尝试传递两个对象时,我的DataSourceRequest始终为null。
这是我的js代码:
function submitForm() {
var grid = $('#denialGrid').data('kendoGrid');
parameterMap = grid.dataSource.transport.parameterMap;
var requestObject = parameterMap({
sort: grid.dataSource.sort(), filter: grid.dataSource.filter(), group: grid.dataSource.group(), page: grid.dataSource.page(),
pageSize: grid.dataSource.pageSize()
});
var formData = $('#BillingForm').serialize();
$.ajax({
type: "POST",
url: '@Url.Action("SaveUpdate", "Home")',
data: {requestObject,formData},
success: alert(JSON.stringify(requestObject)),
})
}
这是我的控制器方法
[HttpPost]
public ActionResult SaveUpdate([DataSourceRequest] DataSourceRequest request, UpdateViewModel vm)
{
return null;
}
我试过了:
data: {requestObject,formData},
data: [requestObject,formData],
data: requestObject, formData,
data: (requestObject,formData),
data: {request: requestObject, vm: formData},
非常感谢任何帮助
答案 0 :(得分:0)
您应该在requestObject中包含formData,并且只传递requestObject
var requestObject = parameterMap({
sort: grid.dataSource.sort(), filter: grid.dataSource.filter(), group: grid.dataSource.group(), page: grid.dataSource.page(),
pageSize: grid.dataSource.pageSize(), formData: $('#BillingForm').serialize()
});
$.ajax({
type: "POST",
url: '@Url.Action("SaveUpdate", "Home")',
data: requestObject,
success: alert(JSON.stringify(requestObject)),
})

我认为serialize()只返回字符串。您需要将其转换为对象。或者你可以尝试这个
[HttpPost]
public ActionResult SaveUpdate([DataSourceRequest] DataSourceRequest request, string formData)
{
return null;
}