【发布时间】:2013-07-09 00:35:02
【问题描述】:
我有以下型号
public class FooContainer
{
public int ID { get; set; }
public string Name { get; set; }
public IList<Foo> Foos { get; set; }
}
public class Foo
{
public string Name {get; set; }
public string Description {get; set;}
}
示例控制器
public class FooController : Controller
{
public ActionResult Index(){
return View(new FooContainer());
}
[HttpPost]
public ActionResult Index(FooContainer model){
//Do stuff with the model
}
}
我想创建一个视图,使用户能够 CRUD Foos。
现有研究
我已阅读以下内容:
http://haacked.com/archive/2008/10/23/model-binding-to-a-list.aspx
http://haacked.com/archive/2008/10/23/model-binding-to-a-list.aspx
连同以下 SO 文章
MVC4 Allowing Users to Edit List Items
MVC4 bind model to ICollection or List in partial
所以我知道如何来回传递一个 IEnumerable,问题是我想传递一些容器,其他属性包括一个 IEnumerable
要求
我希望能够绑定到这个复杂的模型,以便将它完全完整地传递给控制器。假设控制器只渲染视图并在发布时接收 FooController 模型。此外,我想要启用此功能所需的任何相关文章或对 View 语法的引用。
提前致谢
【问题讨论】:
-
嘿,请描述一下 FooController 中的一种方法。
-
也许它可以帮助:google by 'mvc4 custom binders'
-
我正在研究 MVC4 自定义绑定器...它们看起来很酷!
-
如果这没有帮助,请再次在 cmets 中写入。
-
您不需要自定义模型绑定器。
标签: c# asp.net-mvc-4 razor