MVC局部视图和复杂模型

时间:2013-04-10 21:44:26

标签: asp.net-mvc http-post

我正在尝试填充嵌套模型

该模型看起来像这样

public Layout {
   public List<Record> Records {get;set;}
}

public Record {
   public List<PlaceHolder> PlaceHolders {get;set;}
}

public PlaceHolder {
   public string Label {get;set;}
}

当我的表单发布时,使用fiddler,我看到格式为

的键下来的值
Records.Index = 0
Records.PlaceHolders.Index = 0
Records[0].PlaceHolders[0].Label = foo
Records.Index = 0
Records.PlaceHolders.Index = 1
Records[0].PlaceHolders[1].Label = bar
Records.Index = 1
Records.PlaceHolders.Index = 1
Records[1].PlaceHolders[1].Label = boo
...

我必须使用部分视图生成很多这些KeyNames,使用HtmlFieldPrefix设置填充TemplateInfo。

当我查看我的保存控制器时,布局仅部分填充。它拥有Records属性中的所有记录。但是没有一个记录包含PlaceHolders。

我的帖子有什么问题?

1 个答案:

答案 0 :(得分:0)

知道了,我需要这些行

Records.PlaceHolders.Index = 0

拥有记录索引,如此

Records[1].PlaceHolders.Index = 0
相关问题