Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You have to manually fire the validator on your form that was loaded dynamically into your html page.</p> <p>try this:</p> <p>in your view use <code>Ajax.ActionLink</code> to load the content of the partial view into your dialog container to avoid unnecessary JavaScript.</p> <pre><code>@Ajax.ActionLink("AjaxLink", "EditPerson", new { PersonID = model.Id_Person }, new AjaxOptions { UpdateTargetId = "myModalDialog", HttpMethod = "Post",OnSuccess="OpenDialog(myModalDialog)" }) &lt;div id="myModalDialog" title="" style="display: none"&gt; &lt;/div&gt; </code></pre> <p>in you JS file do this</p> <p></p> <pre><code>function OpenDialog(DialogContainerID) { var $DialogContainer = $('#' + DialogContainerID); var $jQval = $.validator; //This is the validator $jQval.unobtrusive.parse($DialogContainer); // and here is where you set it up. $DialogContainer.modal(); var $form = $DialogContainer.find("form"); $.validator.unobtrusive.parse($form); $form.on("submit", function (event) { var $form = $(this); //Function is defined later... submitAsyncForm($form, function (data) { $DialogContainer.modal("hide"); window.location.href = window.location.href; }, function (xhr, ajaxOptions, thrownError) { console.log(xhr.responseText); $("body").html(xhr.responseText); }); event.preventDefault(); }); } //This is the function that will submit the form using ajax and check for validation errors before that. function submitAsyncForm($formToSubmit, fnSuccess, fnError) { if (!$formToSubmit.valid()) return false; $.ajax({ type: $formToSubmit.attr('method'), url: $formToSubmit.attr('action'), data: $formToSubmit.serialize(), success: fnSuccess, error: fnError }); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload