Friday, January 15, 2016

Put an id on a Razor form.

@using (Html.BeginForm("New", "User"))

 
 

...as seen here could be revised like so...

@using (Html.BeginForm("Invoice", "Buyers", FormMethod.Post, new { id = "form"}))

 
 

As much would allow for the following to come after the form to start the validations.

<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript">
</script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript">
</script>
<script type="text/javascript">
   $(function() {
      $("#form").validate({
         rules: {
            Username: { required: true },
            Password: { required: true },
            PasswordConfirmation: { required: true },
            PhoneNumber: { required: true }
         }
      });
   });
</script>

No comments:

Post a Comment