在HttpPost上将嵌套模型与MVC3绑定 [英] Binding nested model with MVC3 on HttpPost

查看:229
本文介绍了在HttpPost上将嵌套模型与MVC3绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是MVC3的新手。

我在表单上有一个提交按钮,我想绑定一个具有2-3个具有许多属性的嵌套对象模型的模型内部。

I have a submit button on a form and I want to bind a model which has 2-3 nested object models with many properties inside.

有没有办法在不使用EditorFor的情况下绑定这些嵌套对象;因此,当我提交表单时,我将对正在返回的模型采用ActionResult(对象模型),嵌套对象使用其值进行建模,而不必在html上实现隐藏值或表单?

Is there a way to bind these nested objects without using EditorFor; so that when I submit the form I will take on ActionResult(Object model) on model that is being returned, the nested object models with their values without having to implement hidden values or forms behind on html?

推荐答案

基本上你需要足够的值来再次识别你的模型。因此,您可以使用隐藏字段中的Id以及要更改的所有属性。
要重新创建模型,只需将Id和通过基本参数更改的值传递给控制器​​操作,或者写一个 model-binder - 恕我直言,这是处理这些情况的最佳方式。

basically you need enough values to identify your model again. So you can go with a Id in a hidden field and all the properties you want to change. To recreate your model either just pass the Id and changed values via basic parameters to your controller-action or write a model-binder - IMHO thats the best way to deal with those situations.

这篇关于在HttpPost上将嵌套模型与MVC3绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆