1

有什么区别:

@Html.LabelFor(model => model.Soluongton, htmlAttributes: new { @class = "control-label col-md-2" })

@Html.LabelFor(model => model.Soluongton, new { htmlAttributes = new { @class = "control-label col-md-2" } })  

什么是htmlAttributes

4

1 回答 1

1
@Html.LabelFor(model => model.Soluongton, htmlAttributes: new { @class = "control-label col-md-2" })

将呈现 HTML 代码:

<label class="control-label col-md-2" for="Soluongton">Soluongton</label>

@Html.LabelFor(model => model.Soluongton, new { htmlAttributes = new { @class = "control-label col-md-2" } })  

将呈现 HTML 代码:

<label for="Soluongton" htmlAttributes="{ class = control-label col-md-2 }">Soluongton</label>

如您所见,第二个@Html.LabelFor将呈现错误的 HTML 输出。

于 2018-10-04T07:09:43.607 回答