I am having the following problem when updating a via AJAX after sending it. For some reason, some hidden fields that are in the returned HTML are not updated, which is strange, because when I run the debugger, they seem to have the correct value.
This is an important part of my form.
<div id="itemPopUpForm"> @{Html.EnableClientValidation();} @Html.ValidationSummary() <div id="formDiv"> @{ Html.RenderPartial("ItemData", Model, new ViewDataDictionary() { { "Machines", ViewBag.Machines }, { "WarehouseList", ViewBag.WarehouseList }, { WebConstants.FORM_ID_KEY, @ViewData[WebConstants.FORM_ID_KEY] } }); } </div> </div>
The partial view then contains hidden fields, such as those that are not updated.
@using (Html.BeginForm("Index", "Item", FormMethod.Post, new { id = "frmItem", name = "frmItem" })) { @Html.AntiForgeryToken() @Html.HiddenFor(model => model.Item.SodID) @Html.HiddenFor(model => Model.Item.ItemID) //The itemID needs updating when an item is copied @Html.HiddenFor(model => model.Item.Delivery.DeliveryAddressID, new { @id = "delAddressID" })
And this is a javascript method that updates the form
function ajaxSave() { if (!itemValid()) return; popup('ajaxSplash'); $.ajax({ type: "POST", url: '@Url.Action("Index")', data: $("#frmItem").serialize(), success: function (html) { console.log(html); $("#formDiv").html(html); initItemPage(); alert("Item was saved successfully"); }, error: function () { popup('ajaxSplash'); onFailure(); } }); }
The action index returns a Partial View "ItemData", and when I check the item model, it has the correct value, but when I see the returned html, it is still set to 0.