I want to replace html helpers by tag helpers in View.
For this I replacing: @model IEnumerable<Person>
by @model IList<Person>
and @Html.DisplayNameFor(model => model.Name)
by <label asp-for="@Model[0].Name"></label>
but what I should use instead: @Html.DisplayFor(modelItem => item.Name)?
<input asp-for="@item.Name" readonly /> ?
It doesn't look right.
UPDATE: Just to clarify question: @Html.DisplayNameFor and <label asp-for both generate labels in html.
@Html.DisplayFor generates just text. Which tag helper can replace it? I don't want to use input just to show text.
When you use
IListthen you can access the property both ways.and if you used
IEnumerable, you need to callToListmethod to access the properties without usingforeach