【发布时间】:2011-11-23 16:32:50
【问题描述】:
我想为作为属性存在于我的 ViewModel 类中的模型列表创建一个编辑器。
ViewModel 类:
public class FooManagementDetailViewModel : ViewModelBase
{
public List<FooPermissionModel> FooPermissions { get; set; }
模型类:
public class FooPermissionModel
{
public string Name { get; set; }
public string Reason { get; set; }
public bool Selected { get; set; }
}
编辑器模板:
@model FooPermissionModel
<table>
<thead>
<tr>
<th>
Heading
</th>
<th>
Heading
</th>
<th>
Heading
</th>
</tr>
</thead>
<tbody>
<tr>
<td>
@Html.TextBoxFor(x => x.Name, new { @readonly = "readonly" })
</td>
<td>
@Html.CheckBoxFor(x => x.Selected)
</td>
<td>
@Html.TextBoxFor(x => x.Reason)
</td>
</tr>
</tbody>
</table>
查看:
<fieldset>
<legend>FooBarTitle</legend>
<div>
@Html.EditorFor(x => x.FooPermissions)
</div>
</fieldset>
我返回的只是名称的单个 div。根本没有结构。 我错过了什么?
谢谢!
【问题讨论】:
-
我在您的模型中没有看到 CompanyName,这是拼写错误吗?
-
你有什么看法?
-
使用EditorForModel不是最好吗?并根据模型来做。不是列表。
标签: c# asp.net-mvc-3 razor