I have form on my page that has the following code
<form class="form">
... bunch of inputs and presentation logic...
<div>
<input type="submit" class="btn btn-primary" id="submit_btn" value="Save Part"/>
<a class="btn" href="/Part/CopyPart/?id=@Model.ID ">Copy Part</a>
<a class="btn" href="/Part/Delete/?id=@Model.ID">Delete Part</a>
<a class="btn" href="/Part/PartList/?selectedType=@Model.PartType">Return To Part List</a>
</div>
@Html.HiddenFor(model => model.ID)
@Html.HiddenFor(model => model.Manufacturer)
@Html.HiddenFor(model => model.DateCreated)
@Html.HiddenFor(model => model.Manufacturer)
@Html.HiddenFor(model => model.IsActive)
@Html.HiddenFor(model => model.PartType)
</form>
and I am trying to use pjax() to submit this form and refresh the containing with some results. My js code is as follows.
$(function() {
$('a').pjax({ container: "#update_panel", timeout: 2000 }).live('click', function() {});
$("#submit_btn").click(function() {
var form = $('#form');
$.pjax({
container: "#update_panel",
timeout: 2000,
url: "@Url.Action("UpdatePart","Part")",
data: form.serialize()
});
});
});
This code submits calls my UpdatePart() action but it passes an empty model to the action? How can I populate the model with the form contents so that it all works?
You are referencing form using an Id, but the form has a class and no id. Try:
or