我正在尝试根据我在联系表单模型中显示的各种字段创建HTML表单。但是,在字段的label
属性中,我想使用一些HTML标记,例如<strong>
和<span>
来区分label
的部分内容,即我瞄准的HTML for is:
<label for="error">
<strong>Error</strong>
- Has the app stopped working?
<span class="small">Did the app crash whilst running?</span>
</label>
当我使用模型/视图方法时。我在模型中声明了一个字段并给它一个名称显示属性,在视图中,label方法选择了这个name属性。但是我无法找到添加额外HTML的方法(即<span class="small">Did the app crash whilst running?</span>
位)
这是我的代码:
型号:
[Display(Name = "Has the app stopped working?")]
public string Error{ get; set; }
查看:
@Html.LabelFor(model => model.Error, htmlAttributes: new { @class = "control-label col-md-2" })
@Html.EditorFor(model => model.Error, new { htmlAttributes = new { @class = "email form-control" } })
@Html.ValidationMessageFor(model => model.Error, "", new { @class = "text-danger" })
我似乎无法在name
属性中添加HTML,而且这种方式似乎也很混乱 - 无论如何都要这样做吗?