1
混得AJAX交右数据我有这样的部分视图:不从for循环
@model InventoryControl.Models.InventoryControlModel
<table class="table_body" style="font-size:x-small">
@if (Model != null)
{
for (var rolcnt = 0; rolcnt < Model.Roles.Count(); rolcnt ++)
{
<tr>
<td>
@Html.DisplayTextFor(x => x.Roles[rolcnt].ItemTypeCode)
</td>
<td>
@Html.CheckBoxFor(x=>x.Roles[rolcnt].Included)
</td>
</tr>
}
}
else
{
<span><i>User has no records for Inventory Control</i></span>
}
局部视图与特定项目类型代码和所包括的标志正确地填充。然后,我尝试用此更改回来:
function AddInventoryRole() {
$.ajax({
type: 'POST',
data: $("#InventoryRoleForm").serializeArray(),
url: '@Url.Action("PostInventoryRoles")',
success: function() {
alert('success');
},
error: function() {
alert('error');
}
});
}
我看到控制器方法中的一些数据。项目类型代码不存在,对于每个条目都是NULL,即使包含的标志在帖子中是正确的。我究竟做错了什么?
[HttpPost]
public ActionResult PostInventoryRoles(InventoryControlModel model)
{
return Json(model);
}