-1

I have a MVC form and i am using JQuery.Validate.js plugin to validate all my controls. Now i had a requirement of making the form to submit the value Asynchronously, so i took advantage of Ajax.BeginForm() and i had to also include jquery.validate.unobtrusive.js plugin to pass the value asynchronously. Now my problem is when i started to use jquery.validate.unobtrusive.js plugin all my validation which i used to validate using jQuery.Validate gone for a toss and the validation is not getting fired, instead my data annotation validation is getting fired which i dont want. This is the link which i am using

<script src="~/Scripts/Jquery/jquery.validate.min.js"></script> 
<script src="~/Scripts/Jquery/additional-methods.min.js"></script> 
<script src="~/Scripts/jquery.validate.unobtrusive.js"></script>
@using (Ajax.BeginForm(new AjaxOptions { HttpMethod = "Post", OnBegin = "onBegin", OnSuccess = "success", OnFailure = "fail", Url = "~/UserManagement/EditingPopup_Create" }))
{
  @Html.LabelFor(model => model.FirstName)
                    @Html.TextBoxFor(model => model.FirstName, new { @class = "form-control", tabindex = 1 })
                    @Html.ValidationMessageFor(model => model.FirstName)
  <input type="submit" value="Submit" class="btn-default" />
}

can anyone help me on how exactly should my approach be and why is this kind of problem arise. Thank you

Lijin Durairaj
  • 4,910
  • 15
  • 52
  • 85
  • Not clear what your asking. Using `Html.BeginForm()` vs `Ajax.BeginForm()` makes no difference to client side validation. –  Sep 12 '16 at 22:48
  • @StephenMuecke i am using Ajax.BeginForm() and i have jQuery.validate to validate all the fields in the form. My issue is when i referenced jquery.validate.unobtrusive.js, all my validation which i used using jquery.validate went for a toss, it is not working – Lijin Durairaj Sep 12 '16 at 22:52
  • It has nothing to do with using `Ajax.BeginForm()`. Are dynamically loading html after the page is first rendered?And what is `additional-methods.min.js`? –  Sep 12 '16 at 22:55
  • @StephenMuecke my question is, 1.is the jquery.validate.unobtrusive.js file required when we use Ajax.BeginForm() 2. does using jquery.validate plugin along with jquery.validate.unobtrusive.js causes any error, cause my form is not getting submitted..thank you – Lijin Durairaj Sep 12 '16 at 22:55
  • @StephenMuecke do you mean from your previous answer that jquery.validate.unobtrusive.js is not required for Ajax.BeginForm() ??? – Lijin Durairaj Sep 12 '16 at 22:57
  • No. If you want to use MVC's client side validation, then you must use `jquery.validate.js` and `jquery.validate.unobtrusive.js`. And what do you mean the form is not submitted? –  Sep 12 '16 at 22:58
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/123189/discussion-between-lijin-john-and-stephen-muecke). – Lijin Durairaj Sep 12 '16 at 22:58

1 Answers1

0

Well i am sorry, it was eventually my mistake. i was using

<script src="~/Scripts/jquery.validate.unobtrusive.js"></script>

when i should have actually used

<script src="~/Scripts/jquery.unobtrusive-ajax.js"></script>

I never knew that jquery.validate.unobtrusive.js & jquery.unobtrusive-ajax.js are both different.

Lijin Durairaj
  • 4,910
  • 15
  • 52
  • 85