从列表框更改事件的Ajaxpost上的模型属性null

我有一个包含列表框的视图。 当用户点击列表框中的项目时,我必须发布到控制器操作方法,以查看列表框中选定/取消选择的项目的值。

因此它会发布到控制器操作,但模型将发布为null。 当我发布到控制器时,我会对表单进行序列化。

在我的应用程序的其他页面中,当我序列化表单并发布到控制器时,模型永远不会为空。 我不确定这个页面是怎么回事,但这里是代码。

JS档案

var serviceEntryURL = '@Url.Action("ServiceSystemSelection", "ServiceEntry")'; $('#systemlstbox').change(function () { // alert('x'); var overlay = $('
loading errorcodes and parts..
').prependTo('body').attr('id', 'overlay'); $.post(serviceEntryURL, $("#form").serialize(), function (data) { // $("#runDatestreeview").remove(); // $("#testExceptiontreeview").remove(); // $("#treeview").remove(); // $("#main").html(data); // $("#ErrorCodeDisplay").empty(); }, "html"); overlay.remove(); });

视图

 @model RunLog.Domain.Entities.ServiceEntry @{ ViewBag.Title = "Create"; Layout = "~/Views/Shared/_Layout.cshtml"; } @using (Html.BeginForm(new { id = "form", enctype = "multipart/form-data" })) { 
Enter a new Service Log Entry

@Html.ValidationSummary(true)
@(ViewBag.ErrorMessage)
@Html.Label("Service Request Number") [Generated]
@Html.Label("Service Request Date / Time") @Html.EditorFor(model => model.ServiceDateTime)
@Html.Label("Technician") @Html.DropDownList("TechnicianID", String.Empty)
@Html.Label("System") @Html.ListBoxFor(model => model.SelectedSystemIDs, new MultiSelectList(ViewBag.SystemID, "Text", "Value", Model.SelectedSystemIDs), new { id = "systemlstbox", name = "listbox" })
}

控制器动作

  [HttpPost] [AcceptVerbs(HttpVerbs.Post)] public ActionResult ServiceSystemSelection(ServiceEntry serviceEntry) { } 

我修复了它,表单序列化行是错误的。

 $('#systemlstbox').change(function () { // alert('x'); $.post(serviceEntryURL, $('form').serialize(), function (data) { }, "html"); });