asp.net mvc 3 - MVC3/Razor Client Validation Not firing -
i trying client validation working in mvc3 using data annotations. have looked @ similar posts including mvc3 client side validation not working answer.
i'm using ef data model. created partial class validations.
[metadatatype(typeof(post_validation))] public partial class post { } public class post_validation { [required(errormessage = "title required")] [stringlength(5, errormessage = "title may not longer 5 characters")] public string title { get; set; } [required(errormessage = "text required")] [datatype(datatype.multilinetext)] public string text { get; set; } [required(errormessage = "publish date required")] [datatype(datatype.datetime)] public datetime publishdate { get; set; } }
my cshtml page includes following.
<h2>create</h2> <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> @using (html.beginform()) { @html.validationsummary(true) <fieldset> <legend>post</legend> <div class="editor-label"> @html.labelfor(model => model.title) </div> <div class="editor-field"> @html.editorfor(model => model.title) @html.validationmessagefor(model => model.title) </div> <div class="editor-label"> @html.labelfor(model => model.text) </div> <div class="editor-field"> @html.editorfor(model => model.text) @html.validationmessagefor(model => model.text) </div> }
web config:
<appsettings> <add key="clientvalidationenabled" value="true" /> <add key="unobtrusivejavascriptenabled" value="true" />
layout:
<head> <title>@viewbag.title</title> <link href="@url.content("~/content/site.css")" rel="stylesheet" type="text/css" /> <script src="@url.content("~/scripts/jquery-1.4.4.min.js")" type="text/javascript"></script>
so, multiline text annotation works , creates text area. none of validations work client side. don't know might missing. ideas?? can post more information if needed. thanks!
1.) try adding following view validating
htmlhelper.clientvalidationenabled = true; htmlhelper.unobtrusivejavascriptenabled = true;
i did not find necessary modify web.config, may remove
<add key="clientvalidationenabled" value="true" /> <add key="unobtrusivejavascriptenabled" value="true" />
good luck! also, try putting in known bad value see if client side validation triggered, required annotation not seem enough display message blank input.
2.) put below scripts in view, should work.
@section scripts { @scripts.render("~/bundles/jqueryval") }
Comments
Post a Comment