Within a Partial View, there is a form(@addName) using Html.Helper classes (TextBoxFor, DropDownListFor, etc).
@model Models.ADP
using (@Html.BeginForm(new { id= @addName}))
{
@Html.TextBoxFor(model => model.EndValue, new { id = @newName, size = "5", style = "margin-right: 10px" })
@Html.HiddenFor(model => model.ModuleTypeId, new { @Value = @ViewBag.ModuleId }
@Html.DropDownListFor(model => model.DPId, @dpList, "Choose an Option...", new { @class = "select" })
}
I intercept the submit in order to post and retrieve new data asynchronously, divId is the div for the whole Partial View.
$('#@saveName').click( function (event) {
event.preventDefault();
$.ajax({
url: '@Url.Action("SaveADP", "Dispense")',
type: 'POST',
data: $('#@addName').serialize(),
success: function (data) {
$('#@divId').html(data);
}
})
})
The SaveADP action is being called, but the only field with a set value is EndValue, the other fields(ModuleTypeId and DPId) have the default values instead of their form values. What am I doing wrong here?
public ActionResult SaveADP(ADP newDP)
is the signature, ADP has the fields StartValue, EndValue, ModifiedDate, DPId, ModuleTypeId, and Duration. I haven't gone beyond that yet since newDP isn't being constructed with correct values.