I am prompted to create a login form, when user input fails validation, a warning window appears.
I have all postings using model-based validation.
Example:
public class LogonViewModel { [Required( ErrorMessage = "User Name is Required")] public string UserName { get; set; } [Required( ErrorMessage = "Password is required")] public string Password { get; set; } }
I have a validation summary on the page:
Html.ValidationSummary()
I would like the summary to be on the page only if the user has javascript disabled. But if the client-side check is triggered, I also want to catch the check event and put the errors in the notification window, as if they were asking me.
My form is basically ...
@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 the things I tried was
<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 to do this. I just want to allow normal error checking and display, but I have the opportunity to do a little more.
source share