Note that there are some explanatory texts on larger screens.

plurals
  1. POasp.net mvc 3 unobstrusive validation issue
    primarykey
    data
    text
    <p>I'm trying to make some Category entity adding form with unobstrusive validation on client side.</p> <p>Here is my entity:</p> <pre><code>public class Category { public Int32 Id { get; set; } [DisplayName("Alias")] [Required(AllowEmptyStrings = false, ErrorMessage = "Have to complete")] [StringLength(100, ErrorMessage = "asdasdasd", MinimumLength = 3)] public String Name { get; set; } [DisplayName("Name1")] [Required(AllowEmptyStrings = false, ErrorMessage = "Have to complete")] public String DisplayName { get; set; } [DisplayName("Name2")] [Required(AllowEmptyStrings = false, ErrorMessage = "Have to complete")] public String DisplayNameTZK { get; set; } [DisplayName("Url")] [DataType(DataType.Url, ErrorMessage = "Url")] public String Uri { get; set; } public Guid AddingGuid { get; set; } public Boolean IsActive { get; set; } ... } </code></pre> <p>Here is my view:</p> <pre><code>@model HSDT.Models.Entities.Category @{ Html.EnableUnobtrusiveJavaScript(); Html.EnableClientValidation(); } @using (Html.BeginForm("", "", null, FormMethod.Post, new { id = "addCategoryForm", name = "addCategoryForm" })) { @Html.AntiForgeryToken() @Html.ValidationSummary(false) &lt;fieldset&gt; &lt;legend&gt;Category&lt;/legend&gt; &lt;div class="editor-label"&gt; @Html.LabelFor(model =&gt; model.Name) &lt;/div&gt; &lt;div class="editor-field"&gt; @Html.EditorFor(model =&gt; model.Name) @Html.ValidationMessageFor(model =&gt; model.Name) &lt;/div&gt; &lt;div class="editor-label"&gt; @Html.LabelFor(model =&gt; model.DisplayName) &lt;/div&gt; &lt;div class="editor-field"&gt; @Html.EditorFor(model =&gt; model.DisplayName) @Html.ValidationMessageFor(model =&gt; model.DisplayName) &lt;/div&gt; &lt;div class="editor-label"&gt; @Html.LabelFor(model =&gt; model.DisplayNameTZK) &lt;/div&gt; &lt;div class="editor-field"&gt; @Html.EditorFor(model =&gt; model.DisplayNameTZK) @Html.ValidationMessageFor(model =&gt; model.DisplayNameTZK) &lt;/div&gt; &lt;div class="editor-label"&gt; @Html.LabelFor(model =&gt; model.Uri) &lt;/div&gt; &lt;div class="editor-field"&gt; @Html.EditorFor(model =&gt; model.Uri) @Html.ValidationMessageFor(model =&gt; model.Uri) &lt;/div&gt; &lt;div class="editor-label"&gt; @Html.LabelFor(model =&gt; model.AddingGuid) &lt;/div&gt; &lt;div class="editor-field"&gt; @Html.EditorFor(model =&gt; model.AddingGuid) @Html.ValidationMessageFor(model =&gt; model.AddingGuid) &lt;/div&gt; &lt;div class="editor-label"&gt; @Html.LabelFor(model =&gt; model.IsActive) &lt;/div&gt; &lt;div class="editor-field"&gt; @Html.EditorFor(model =&gt; model.IsActive) @Html.ValidationMessageFor(model =&gt; model.IsActive) &lt;/div&gt; &lt;p&gt; &lt;input type="submit" value="Create" /&gt; &lt;/p&gt; &lt;/fieldset&gt; } </code></pre> <p>Now I left all my inputs emty and tried to validate this form to get the errors shown in my model using:</p> <pre><code>$("#addCategoryForm").validate().valid() </code></pre> <p>But I get <code>true</code>(and no errors) as a result, but should be <code>false</code> because in the data annotation I added <code>[Required]</code> attribute for few fields. What I'm doing wrong?</p> <p>Thanks for any advance.</p> <p><strong>EDIT-1</strong></p> <p>Here is my config:</p> <pre><code> &lt;appSettings&gt; &lt;add key="ClientValidationEnabled" value="true" /&gt; &lt;add key="UnobtrusiveJavaScriptEnabled" value="true" /&gt; &lt;/appSettings&gt; </code></pre> <p>Here is references:</p> <pre><code> &lt;script src="@Url.Content("~/Scripts/jquery-1.6.2.min.js")" type="text/javascript"&gt;&lt;/script&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; </code></pre>
    singulars
    1. This table or related slice is empty.
    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