如何使用 DisplayFor 从后端在我的视图中显示数据
How to show data in my view from the backend using DisplayFor
如何在我的视图中显示此数据{ TextCode = "Hello", Description = "Hello, How are you ",Text = "Great" }
我的密码是
@Html.DisplayFor(model => model.Texts[].Description);
我想以这种方式显示它,但是如何指定确切的特定内容 textCode
,我不能只将索引放在 Texts[]
中,因为稍后当我添加更多文本时索引可能会更改
不能这样使用数组,必须迭代:
@foreach(var item in Model.Texts)
{
@Html.DisplayFor(m => item.Description)
}
您使用了 model.Texts[]
。您似乎在使用 List<Texts>
简单的你 foreach
循环。试试这个
@foreach(var item in Model.Texts)
{
@Html.DisplayFor(m => item.Description)
}
这个循环遍历每个 Texts
。
如何在我的视图中显示此数据{ TextCode = "Hello", Description = "Hello, How are you ",Text = "Great" }
我的密码是
@Html.DisplayFor(model => model.Texts[].Description);
我想以这种方式显示它,但是如何指定确切的特定内容 textCode
,我不能只将索引放在 Texts[]
中,因为稍后当我添加更多文本时索引可能会更改
不能这样使用数组,必须迭代:
@foreach(var item in Model.Texts)
{
@Html.DisplayFor(m => item.Description)
}
您使用了 model.Texts[]
。您似乎在使用 List<Texts>
简单的你 foreach
循环。试试这个
@foreach(var item in Model.Texts)
{
@Html.DisplayFor(m => item.Description)
}
这个循环遍历每个 Texts
。