I have form in mvc 4 that don't make validation on client side.
The validation happen only only on the server side.
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
<div class="editor-label">
@Html.LabelFor(model => model.Name)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Name)
@Html.ValidationMessageFor(model => model.Name)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Phone)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Phone)
@Html.ValidationMessageFor(model => model.Phone)
</div>
<p>
<input type="submit" value="Send" />
</p>
}
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}
the bundle code is:
bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
"~/Scripts/jquery.unobtrusive*",
"~/Scripts/jquery.validate*"));
I also checked the web.config settings:
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
The model I using is:
public class ContactUs
{
[Required]
public string Name { get; set; }
[Required]
public string Phone { get; set; }
}
The page is inside the _Layout file. Scripts version: jquery 2.0.3s and jQuery Validation Plugin 1.11.1
All the scripts is working and exist on the source code of the page.
What can be the problem?
I added link to the CDN script http://ajax.aspnetcdn.com/ajax/mvc/3.0/jquery.validate.unobtrusive.min.js and now it's working.
After looking on my project history I found that for some reason when I updated my NuGet packages it removed this script from my project and then my client side validations stop working.
I tried to add this script with NuGet packages like "Microsoft jQuery Unobtrusive Validation" or "Microsoft jQuery Unobtrusive Ajax" and some more packages like this and it didn't fix the problem so I added the CDN script and it worked.