Note that there are some explanatory texts on larger screens.

plurals
  1. POMVC3/Razor Client Validation Not firing
    primarykey
    data
    text
    <p>I am trying to get client validation working in MVC3 using data annotations. I have looked at similar posts including this <a href="https://stackoverflow.com/questions/4706174/mvc3-client-side-validation-not-working">MVC3 Client side validation not working</a> for the answer. </p> <p>I'm using an EF data model. I created a partial class like this for my validations.</p> <pre><code>[MetadataType(typeof(Post_Validation))] public partial class Post { } public class Post_Validation { [Required(ErrorMessage = "Title is required")] [StringLength(5, ErrorMessage = "Title may not be longer than 5 characters")] public string Title { get; set; } [Required(ErrorMessage = "Text is required")] [DataType(DataType.MultilineText)] public string Text { get; set; } [Required(ErrorMessage = "Publish Date is required")] [DataType(DataType.DateTime)] public DateTime PublishDate { get; set; } } </code></pre> <p>My cshtml page includes the following. </p> <pre><code>&lt;h2&gt;Create&lt;/h2&gt; &lt;script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"&gt;&lt;/script&gt; &lt;script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"&gt;&lt;/script&gt; @using (Html.BeginForm()) { @Html.ValidationSummary(true) &lt;fieldset&gt; &lt;legend&gt;Post&lt;/legend&gt; &lt;div class="editor-label"&gt; @Html.LabelFor(model =&gt; model.Title) &lt;/div&gt; &lt;div class="editor-field"&gt; @Html.EditorFor(model =&gt; model.Title) @Html.ValidationMessageFor(model =&gt; model.Title) &lt;/div&gt; &lt;div class="editor-label"&gt; @Html.LabelFor(model =&gt; model.Text) &lt;/div&gt; &lt;div class="editor-field"&gt; @Html.EditorFor(model =&gt; model.Text) @Html.ValidationMessageFor(model =&gt; model.Text) &lt;/div&gt; } </code></pre> <p>Web Config:</p> <pre><code>&lt;appSettings&gt; &lt;add key="ClientValidationEnabled" value="true" /&gt; &lt;add key="UnobtrusiveJavaScriptEnabled" value="true" /&gt; </code></pre> <p></p> <p>Layout:</p> <pre><code>&lt;head&gt; &lt;title&gt;@ViewBag.Title&lt;/title&gt; &lt;link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" /&gt; &lt;script src="@Url.Content("~/Scripts/jquery-1.4.4.min.js")" type="text/javascript"&gt;&lt;/script&gt; </code></pre> <p></p> <p>So, the Multiline Text annotation works and creates a text area. But none of the validations work client side. I don't know what i might be missing. Any ideas?? i can post more information if needed. Thanks!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload