edi*_*ode 15 asp.net-mvc html5 razor
我在MVC中有以下视图,我收到警告消息: 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>
}
Run Code Online (Sandbox Code Playgroud)
想知道为什么我会收到这个警告以及我需要做些什么来解决这个问题.
Chr*_*ris 29
要防止Visual Studio错误地警告您"Element 'legend' occurs too few times"
需要更正Visual Studio的HTML和XHTML验证文件.
然后,VS会将<legend>
标记视为标记内的可选项<fieldset>
(根据规范).
为此,您需要编辑两个文件:html_5.xsd
和xhtml_5.xsd
.对于VS2010,这些可以在(例如)中找到:
C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\Packages\schemas\html\
采取的步骤:
关闭Visual Studio
使用文本编辑器打开html_5.xsd
上面文件夹中的文件.
找到以下行:
(注意有两行相似,第一行是正确的,第二行需要编辑):
<xsd:element name="legend" type="legendType" minOccurs="1" maxOccurs="1" />
编辑该行以阅读:
<xsd:element name="legend" type="legendType" minOccurs="0" maxOccurs="1" />
保存文件
xhtml_5.xsd
对同一文件夹中的文件重复此过程
现在启动Visual Studio并查看HTML5文件 - 警告将消失.
我希望这有助于其他人,我希望.xsd文件将在未来的更新中得到纠正.
更新:
您需要找到的行可能是:
<xsd:element ref="legend" minOccurs="1" maxOccurs="1" vs:firstchild="true"/>
如果是,请将minOccurs="1"
属性更改为minOccurs="0"
sha*_*bus 23
根据HTML 5规范,<legend>
标签不是a中的必需元素<fieldset>
.
legend元素表示图例元素的父字段集元素的其余内容的标题(如果有).
文档:http://www.w3.org/TR/html5/forms.html#the-legend-element
在您的情况下,它只是Visual Studio或插件提供的警告.它不是必需的,可能有一种方法可以在工具 - 选项 - 文本编辑器 - HTML - 验证下压制警告.在这里,您还可以切换验证目标(HTML 5,XHTML 1等)
Ver*_*ion 11
图例集中的图例是可选的.
但试试这个,摆脱警告:
<fieldset>
<legend>User</legend>
@Html.TextBoxFor(model => model.FullName)
</fieldset>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
12869 次 |
最近记录: |