Finally, I got a solution.
First of all, my forms have never been associated with validation callbacks provided by the code inside the MicrosoftMvcJQueryValidation.js script. This is because I use jQuery dialogs and the form is inside the dialog and the script is on the main page.
My first attempt at a solution was to modify MicrosoftMvcJQueryValidation.js . In particular, I added the EnableClientSideValidation() function, where I moved the code that was in the $(document).ready function, as in the following code example
function EnableClientSideValidation() { var allFormOptions = window.mvcClientValidationMetadata; if (allFormOptions) { while (allFormOptions.length > 0) { var thisFormOptions = allFormOptions.pop(); __MVC_EnableClientValidation(thisFormOptions); } } } $(document).ready(function () { EnableClientSideValidation(); });
Then I called the same function inside the script block that I put in the markup code of the $(document).ready() function dialog
With firebug, I placed a breakpoint inside the EnableClientSideValidation() function, and then experienced the fact that it was only called when the main page was ready, but not from the dialog. This was due to the fact that I had my own "dialog" script inside the <form>...</form> , so the script did not work.
Code like this
<% using (Html.BeginForm()) { %> //DIALOG FORM CODE WAS HERE <script type="text/javascript"> $(document).ready(function () { EnableClientSideValidation(); }); </script> <% } %>
has been changed to
<% using (Html.BeginForm()) { %> //DIALOG FORM CODE WAS HERE <% } %> <script type="text/javascript"> $(document).ready(function () { EnableClientSideValidation(); }); </script>
Finally it all started! I would like to thank vandalo and kdawg for their help in finding a solution. There was something else missing, but your answers stimulated my head.
I am posting this for another who may have the same problem.
source share