[英]@html.DisplayFor not displaying data
我有以下观点给我带来了问题:
@model List<Scheduling_Application.ViewModel.ScheduleMap>
<h2>Map</h2>
<p>
@Html.ActionLink("Create New", "Create")
</p>
<table class="MainTable">
<tr>
<th>
Hour
</th>
<th>
Field 1
</th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.TimeHour)
</td>
<td>
<table class="MemberTable">
@foreach (var member in item.MembersFieldOne)
{
<tr>
<td>
@Html.HiddenFor(m => member.ID);
@Html.DisplayFor(m => member.FirstName);
@Html.TextBoxFor(m => member.FirstName);
</td>
</tr>
}
<tr>
<td>
@Html.ActionLink("Add New", "Create", "Session");
</td>
</tr>
</table>
</td>
</tr>
}
</table>
我的问题是@ html.displayfor(m => member.FirstName)将不显示任何数据,但TextBoxFor将显示数据。 该模型已正确设置并正在加载到视图中,但为什么DisplayFor Work不起作用?
一种解决方法是只编写自己的字符串模板。 这些(带有默认项目设置)将分别使用Html.DisplayFor(x => x.MyString)和Html.EditorFor(x => x.MyString)呈现。
查看/共享/ DisplayTemplates / String.cshtml
@model string
@Model
查看/共享/ EditorTemplates / String.cshtml
@model string
@Html.TextBoxFor(x => x)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.