Can anyone tell me why client side validation is not working in my MVC 4 application.
@Scripts.Render("~/bundles/jquery")
@R
For me this was a lot of searching. Eventually I decided to use NuGet instead of downloading the files myself. I deleted all involved scripts and scriptbundles and got the following packages (latest versions as of now)
Then I added these bundles to the BundleConfig file:
bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
"~/Scripts/jquery-{version}.js"));
bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
"~/Scripts/jquery.validate.js",
"~/Scripts/jquery.validate.unobtrusive.js",
"~/Scripts/jquery.unobtrusive-ajax.js"));
I added this reference to _Layout.cshtml:
@Scripts.Render("~/bundles/jquery")
And I added this reference to whichever view I needed validation:
@Scripts.Render("~/bundles/jqueryval")
Now everything worked.
Don't forget these things (many people forget them):
<script src="/Scripts/jquery.unobtrusive-ajax.js"></script>
<script src="/Scripts/jquery.validate.js"></script>
<script src="/Scripts/jquery.validate.unobtrusive.js"></script>
This code worked for me.
I created this html <form action="/StudentInfo/Edit/2" method="post" novalidate="novalidate">
where the novalidate="novalidate"
was preventing the client-side jQuery from executing, when I removed novalidate="novalidate"
, client-side jQuery was enabled and stared working.
I had an issue with validation, the form posts then it validates,
This Doesn't work with jquery cdn
<script type="text/javascript" src="//code.jquery.com/jquery-1.11.0.js"></script>
<script src="~/Scripts/jquery.validate.min.js"></script>
<script src="~/Scripts/jquery.validate.unobtrusive.min.js"></script>
This Works without jquery cdn
<script src="~/Scripts/jquery-1.7.1.min.js"></script>
<script src="~/Scripts/jquery.validate.min.js"></script>
<script src="~/Scripts/jquery.validate.unobtrusive.min.js"></script>
Hope helps someone.
the line below shows you haven't set an DataAttribute like required on AgreementNumber
<input id="AgreementNumber" name="AgreementNumber" size="30" type="text" value="387893" />
you need
[Required]
public String AgreementNumber{get;set;}
Use:
@Html.EditorFor
Instead of:
@Html.TextBoxFor