Try adding an OnBegin callback to AjaxOptions and this should work.
function validateForm() { return $('form').validate().form(); } @using (Ajax.BeginForm("Create", "Part", null, new AjaxOptions { UpdateTargetId = "update_panel", OnBegin = "validateForm" })) ...
If this does not work for you, an alternative solution could be to submit the form using jQuery. That would be my preferred solution.
<div id="result"></div> @using (Html.BeginForm()) { <h3>New @Model.PartType</h3> <p>Serial Number: <strong> @Html.EditorFor(model => model.SerialNumber) @Html.ValidationMessageFor(model => model.SerialNumber) </strong> </p> <p> Name: <strong> @Html.EditorFor(model => model.Name) @Html.ValidationMessageFor(model => model.Name) </strong> </p> ...... more relatively boiler plate code here...... <p> <input type="submit" class="btn primary" value="Save Part"/> </p> }
JQuery / JS function to submit form
$(function () { $('form').submit(function () { $.validator.unobtrusive.parse($('form')); //added if ($(this).valid()) { $.ajax({ url: this.action, type: this.method, data: $(this).serialize(), success: function (result) { $('#result').html(result); } }); } return false; }); });
source share