asp.net mvc 3 - MVC3 Razor JQuery client side validation with an additional alert box -


i being asked create login form when user input doesn't pass validation pops alert box.

i have wire using model based validation.

ex:

 public class logonviewmodel     {         [required( errormessage = "user name required")]         public string username { get; set; }          [required( errormessage = "password required")]         public string password { get; set; }     } 

i have validation summary on page:

html.validationsummary() 

i summary on page in case user has javascript off. if client side validation fires want catch validation event , put errors alert box being asked.

my form ...

@html.validationsummary()  @using (html.beginform(null, null, formmethod.post, new { id = "loginform" }))      {       username: @html.textboxfor(m => m.username) <br/>       password: @html.textboxfor(m => m.password) <br/>       <input type="submit" value="login"/>       } 

one of things tried

<script language="javascript">         $(document).ready(function () {              $("#loginform").validate({                 invalidhandler: function (form, validator) {                     var errors = validator.numberofinvalids();                     if (errors) {                         alert(errors);                     }                 }             });         });        </script> 

i can't figure out how make work. want allow normal validation , showing of errors have opportunity bit more.

one solution modify onerrors function in jquery.validate.unobtrusive.js. function readable.


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -