在一个动作中绑定两个相同类型的对象
我有一个页面收集同一类型的两个对象的信息。提交页面时,处理所提交信息的操作正在尝试使用模型绑定,类似于:
public ActionResult Submit(Person parent, Person child)
{
//Do some stuff
}
它成功绑定其中一个,但无法成功绑定另一个。有谁有任何建议/资源等可以帮助我让它发挥作用吗?
如果需要,我可以修改/重命名并发布各个部分的实际代码。
I have a page that collects information on two objects of the same type. When the page is submitted the action that handles the processing of the information submitted is attempting to use model binding, something similar to:
public ActionResult Submit(Person parent, Person child)
{
//Do some stuff
}
It manages to bind one of them successfully but not the other. Does anyone have any suggestions/resources etc that could help me get this to work?
If needed I can gut/rename and post the actual code for the various pieces.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
解决方案与我的 问题是我前几天发布的(不过我根本不会称这是一个骗局)。
您需要做的只是在输入中包含参数名称,例如:
它应该会自动工作。
(我认为这只是MVC2,你没有提到你使用的是1还是2)
The solution to this is very much similar to the solution to my question that I posted the other day (I wouldn't at all call this a dupe though).
What you need to do is just include the parameter name in your inputs, eg:
and it should all automagically work.
(I think this is MVC2 only, you didn't mention whether you were using 1 or 2)
拥有一个包含两个人实例的 ParentChild 模型是否有意义?
我认为我还没有见过任何像这样尝试在帖子上绑定两个模型的例子。
Would it make sense to have a ParentChild Model with two person instances in it?
I don't think I've seen any examples like this trying to bind two models on post.