1
我想在視圖中用標記幫助程序替換HTML幫助程序。用標記幫助程序替換HTML幫助程序
爲此,我更換:@model IEnumerable<Person>
通過@model IList<Person>
和@Html.DisplayNameFor(model => model.Name)
通過<label asp-for="@Model[0].Name"></label>
但我應該使用:@Html.DisplayFor(modelItem => item.Name)
?
<input asp-for="@item.Name" readonly />
?
它看起來不正確。
UPDATE:只是爲了澄清問題:@Html.DisplayNameFor
和<label asp-for
都生成HTML標籤。
@Html.DisplayFor
只生成文本。哪個標籤幫手可以代替它?我不想用input
來顯示文字。
問題訪問屬性是:我應該使用輸入只是爲了顯示信息?它會在html中生成文本框。 – Alexan
我想要與@ Html.DisplayFor相同的結果,但使用標籤助手。 – Alexan
對於顯示信息,您可以像這樣使用帶有剃鬚刀的HTML標籤。 '
@foreach(在模型VAR項) {- @ item.Name
}
' – Ahmar