假设我有一个类似的模型层次结构:
public class TabModel
{
public PolicyModel Policy {get;set;}
}
public class PolicyModel
{
public IEnumerable<PersonModel> Insured {get;set;}
}
public class PersonModel
{
public string Name {get;set;}
}
我希望在视图中使用Person Name
的编辑器在网格中渲染网格。
我知道如果我能让html像这样:
<input name="Policy.Insured[0].Name" />
<input name="Policy.Insured[1].Name" />
...
etc
在帖子上,我的主要模型将有一个政策,该政策将有一些名字的保险。
我的剃须刀中有什么要求让它自动化?
我敢打赌一个十二个甜甜圈在框架中有什么东西在迭代一个集合时知道Collection[N].PropertyName
但是我不知道如何调用它。
答案 0 :(得分:0)
如果我把:
@Html.EditorFor(model => model.Policy.Insured)
并在Views\Shared\EditorTemplates
文件夹中放置PersonModel.cshtml
,然后在该文件中创建我的编辑器,它就像我希望的那样工作。