I am trying to understand why my MVC Data Annotations are not rendering the HTML 5 required tag. I think the problem is HTML5 & MVC related not JQuery validate.
According to documentation here it is supported in all browsers yet the three I dev against, IE, Chrome, Firefox are not rendering the attribute?
My scenario I thought was pretty simplistic.
MVC controller populates a model then passes to the view. User completes fields and clicks submit. Validation ALWAYS passes even if the fields are left blank? The model state is invalid so the controller kicks it back but I would have expected client side validation to have caught the empty fields. I have a jsfiddle to demonstrate but first let me provide the model.
public partial class FinRecordModel
{
[Required]
public virtual string FinName { get; set; }
[Required]
public virtual string PageLocation { get; set; }
}
The view:
@Html.LabelFor(model => model.FinName):
</td>
<td class="adminData">
@Html.EditorFor(model => model.FinName)
@Html.ValidationMessageFor(model => model.FinName)
</td>
</tr>
<tr>
<td class="adminTitle">
@Html.LabelFor(model => model.PageLocation):
</td>
<td class="adminData">
@Html.EditorFor(model => model.PageLocation)
@Html.ValidationMessageFor(model => model.PageLocation)
</td>
I created this jsfiddle that uses the html as rendered by the browser and validation always passes.
http://jsfiddle.net/ramjet/mo0v2b76/5/
Now if I add the required attribute as seen in this jsfiddle then everything works as expected so just wondering what is going on???
http://jsfiddle.net/ramjet/mo0v2b76/6/
If this is HTML5 / MVC goofiness as the new HTML standard is still getting incorporated into the web then perhaps I should have a document onload function using jquery to add the required attribute to the input field?
Thank You for your input / advice.