收集回发的正确签名?
我有一个带有集合的实体,例如:Product.Parts - 当我渲染 Product 的视图时,我调用 .EditorFor(x => x.Parts),它将我的字段命名为:Parts[0].Name。
如何声明接收回发的控制器方法,以便它可以将这些字段名称重组为有用的内容?
我最初尝试过:
[HttpPost] public ActionResult Create(Product entity)
这似乎给了我一个正确类型的对象,但都是空的(属性为空)。然后我尝试:
[HttpPost] public ActionResult Create(List<Product> entity)
但在这种情况下实体本身为空。另外,这没有帮助: [HttpPost] public ActionResult Create(IList实体) 我想我总能做到这一点:
[HttpPost] public ActionResult Create(FormCollection form)
{
var Name = form["Product[0].Name"];
}
但这太恶心了!帮助?
I haven an entity with a collection, something like: Product.Parts - when I render a view for Product, I call .EditorFor(x => x.Parts), which names my fields like: Parts[0].Name.
how do I declare my controller method that receives the postback so it can recompose those field names into something useful?
I originally tried:
[HttpPost] public ActionResult Create(Product entity)
which seemed to give me an object of the right type but was all empty (properties were null). then I tried:
[HttpPost] public ActionResult Create(List<Product> entity)
but in this case entity itself is null. also, this didn't help:
[HttpPost] public ActionResult Create(IList entity)
I guess I can always do this:
[HttpPost] public ActionResult Create(FormCollection form)
{
var Name = form["Product[0].Name"];
}
but that's eecky! help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你的第一次尝试应该有效...也许看看 Firefox 或 Chrome 中发布的值?
your 1st attempt should have worked... maybe have a look at the posted values in firefox or chrome?