I have the following View in MVC and I get the warning message: Validation (HTML5): Element 'legend' occurs too few times
@model Berwin.Models.ViewModels.UserViewModel
@{
ViewBag.Title = "Press";
}
<h2>Press Area</h2>
@using (Html.BeginForm("Register", "PressController", FormMethod.Post))
{
<fieldset>
@Html.TextBoxFor(model => model.FullName)
</fieldset>
<fieldset>
@Html.TextBoxFor(model => model.Company)
</fieldset>
<fieldset>
@Html.TextBoxFor(model => model.EmailAddress)
</fieldset>
<fieldset>
@Html.CheckBoxFor(model => model.JoinMailingList)
</fieldset>
}
Would like to know why I am getting this warning and what I need to do to fix this.
To prevent Visual Studio incorrectly warning you that the
"Element 'legend' occurs too few times"you need to correct Visual Studio’s HTML and XHTML validation files.VS will then treat the
<legend>tag as optional inside a<fieldset>tag (as per the spec).To do so, there are two files you need to edit:
html_5.xsdandxhtml_5.xsd. For VS2010 these are found in (e.g.):C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\Packages\schemas\html\Steps to take:
Close Visual Studio
Using a text editor open the file
html_5.xsdfound in the folder above.Locate the following line:
(note there are two lines which are similar, the first is correct, the second needs editing):
Edit the line to read:
Save the file
Repeat the process for the file
xhtml_5.xsdwhich is in the same folderNow start Visual Studio and view your HTML5 file – the warning will be gone.
I hope that helps others, and I hope the .xsd files will be corrected in a future update.
UPDATE:
The line you need to find may be:
If so, change the
minOccurs="1"attribute tominOccurs="0"