ASP.NET MVC2 - 在形式上具体领域通过特定对象传递? [英] ASP.NET MVC2 - specific fields in form pass via a specific object?

查看:130
本文介绍了ASP.NET MVC2 - 在形式上具体领域通过特定对象传递?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在数据库中,我有Contacts表:

In database I have Contacts table:

ContactID (int)
FirstName (varchar)
LastName (varchar)
...
XmlFields (xml) // This field is xml type

要创建新的联系人,我创建了两个类 - 一个用于常规领域和其他显示从 XmlFields 字段的字段

To create a new contact, I created two classes - one for regular fields and other to display fields from XmlFields field.

在控制器,我有以下:

public ActionResult Create(Contact contact, FormCollection collection)
...

常规领域我赶上与联系人对象和那些需要被存储为XML的 XmlFields 我试着与对象赶上。问题是,对象捕捉所有领域,所以我不知道是否可以发布到一个特定的对象时,这样我可以很容易地与他们操纵隔离XML领域。
我需要在这分离的对象,因为这些XML领域将要动态生成的,将是为每个用户不同的。

Regular field I catch with contact object and those that need to be stored as xml in XmlFields I try to catch with collection object. Problem is that collection object catches all fields, so I wonder if it is possible to isolate xml fields when posting to a specific object so that I can easily manipulate with them. I need this in separated objects because these xml fields are going to be generated dynamically and will be different for every user.

在前进,结果谢谢

Thanks in advance,
Ile

推荐答案

您可以单独像字段:

public ActionResult Create(int ContactID, string FirstName)

和原始数据传递到XML ......没有任何自动方式为MVC知道在哪里什么数据推到,除非你考虑创建一个自定义的模型绑定:<一href=\"http://davidhayden.com/blog/dave/archive/2008/09/08/CustomModelBinderMoreUIValidationASPNETMVC.aspx\" rel=\"nofollow\">http://davidhayden.com/blog/dave/archive/2008/09/08/CustomModelBinderMoreUIValidationASPNETMVC.aspx这是另一种有效的选择。

And pass the raw data to the XML... There isn't any automatic way for MVC to know where to push what data to, unless you consider creating a custom model binder: http://davidhayden.com/blog/dave/archive/2008/09/08/CustomModelBinderMoreUIValidationASPNETMVC.aspx which is another valid option.

心连心。

这篇关于ASP.NET MVC2 - 在形式上具体领域通过特定对象传递?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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