如何在我的观看{ TextCode = "Hello", Description = "Hello, How are you ",Text = "Great" }
我的代码是
@Html.DisplayFor(model => model.Texts[].Description);
我希望以这种方式显示它,但是如何指定确切的特定textCode
,我不能将索引放在Texts[]
中,因为索引可能会在我添加更多文本时稍后更改
答案 0 :(得分:1)
您使用了model.Texts[]
。看起来您正在使用List<Texts>
简单的foreach
循环。试试这个
@foreach(var item in Model.Texts)
{
@Html.DisplayFor(m => item.Description)
}
这循环遍历每个Texts
。
答案 1 :(得分:0)
你不能以这种方式使用数组,你必须迭代:
@foreach(var item in Model.Texts)
{
@Html.DisplayFor(m => item.Description)
}