Validation Firing on Page Load

user1287132 picture user1287132 · Mar 23, 2012 · Viewed 8k times · Source

Currently, I have an MVC 3 app using the Razor View engine. I have unobtrusive validation enabled. The problem is that for some reason, on page load, my Edit View is displaying errors for required fields (even though the fields have a value). Has anyone else ran into this? Any suggestions for resolving this? Thanks.

Sample Field with problem:

    <div class="full">
            <label>Description:</label>
            @Html.EditorFor(x=>x.Description, new{@class="super-textarea"})
            @Html.ValidationMessageFor(x => x.Description)

        </div>

Data Annotations on Model:

     [Required, DataType(DataType.MultilineText)]
    public virtual string Description { get; set; }

WebConfig enabled settings:

     <add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />

And of course the proper jquery files....

Answer

Aaron Hoffman picture Aaron Hoffman · Aug 23, 2012

You can also clear the errors from the ModelState

ModelState.Clear();