Search code examples
asp.net-mvcjquery-validateunobtrusive-validationajax.beginform

How to disable jquery.unobstrusive and enable jquery.validate in MVC forms


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


Solution

  • 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.