MVC 6 Tag Helpers and foreach

感情迁移 提交于 2019-12-08 23:17:52

问题


What would I give to asp-for property of a label tag helper in order to display items from a collection. The code below generates a compilation error.

@foreach (var item in Model)
{
    <label asp-for="item.BookingCode"></label>
}

回答1:


The @ character escapes the default model lambda code. Therefore you can type:

@foreach (var item in Model)
{
    <label asp-for="@item.BookingCode"></label>
}



回答2:


I Have a simple way to do a list and show properties of it.

List<string> razones = new List<string>();
foreach (var item in _context.Reason)
{
    razones.Add (item.Description);
}
System.Diagnostics.Debug.WriteLine(razones.Count);


来源:https://stackoverflow.com/questions/31903972/mvc-6-tag-helpers-and-foreach

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!