KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I have having a lot of trouble getting validation to work on MVC3. It works fine when I just load the page directly, but it does not validate when I use jquery AJAX POST: This form is loaded using $('#modal-dialog').load('/DartsMVC/Restaurant/Edit/13') , This is the rendered HTML: <form action="/DartsMVC/Restaurant/Edit/13" method="post"> <fieldset> <legend>Restaurant</legend> <input data-val="true" data-val-number="The field RestaurantID must be a number." data-val-required="The RestaurantID field is required." id="RestaurantID" name="RestaurantID" type="hidden" value="13"> <div class="editor-label"> <label for="Name">Name</label> </div> <div class="editor-field"> <input class="text-box single-line" data-val="true" data-val-required="The Name field is required." id="Name" name="Name" type="text" value="furaibo"> <span class="field-validation-valid" data-valmsg-for="Name" data-valmsg-replace="true"></span> </div> <p> <input type="submit" value="Save" class="ui-button ui-widget ui-state-default ui-corner-all" role="button" aria-disabled="false"> </p> </fieldset> </form> AJAX POST is used by intercepting the form/submit. The modal dialog pops up and closes itself after the post completes. I would like to validate the form before sending the post: // force change the submit data to an ajax POST (usually 'save', 'delete' button) $('#modal-dialog').delegate('form', 'submit', function (e) { e.preventDefault(); var form = $(this); form.validate(); // does nothing if (form.valid()) { $.ajax({ url: form.attr('action'), type: "POST", data: form.serialize(), success: function (data) {
Tags (comma-separated)
Save Edits
Cancel