代码如下所示:
@Html.LabelFor(m => m.FormModel.Position, Model.Company.DefaultEmployee.ToStringOrDefault())
HTML看起来像这样:
<label for="FormModel.Position" >Programmer</label>
(&#34;程序员&#34;是由Model.Company.DefaultEmployee.ToStringOrDefault()
方法生成的字符串)
我试过了:
@Html.LabelFor(m => m.FormModel.Position, Model.Company.DefaultEmployee.ToStringOrDefault(), new {id = "position-label"})
但它不起作用。
这就是Html扩展的样子:
public static MvcHtmlString LabelFor<TModel, TValue>(this HtmlHelper<TModel> html, Expression<Func<TModel, TValue>> expression, string labelText, object htmlAttributes)
{
return LabelFor(html, expression, labelText, new RouteValueDictionary(htmlAttributes));
}