【问题标题】:MVC partial views, and complex ModelsMVC 局部视图和复杂模型
【发布时间】:2013-04-10 21:44:26
【问题描述】:

我正在尝试填充嵌套模型

模型看起来像这样

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。

我的帖子键有什么问题?

【问题讨论】:

    标签: asp.net-mvc http-post


    【解决方案1】:

    知道了,我需要这些行

    Records.PlaceHolders.Index = 0
    

    要有记录索引,像这样

    Records[1].PlaceHolders.Index = 0
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-12-06
      • 2015-04-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-20
      • 1970-01-01
      相关资源
      最近更新 更多