ASP.NET MVC2 - 表单中的特定字段通过特定对象传递?
在数据库中,我有“联系人”表:
ContactID (int)
FirstName (varchar)
LastName (varchar)
...
XmlFields (xml) // This field is xml type
为了创建新联系人,我创建了两个类 - 一个用于常规字段,另一个用于显示 XmlFields
字段中的字段。
在控制器中,我有以下内容:
public ActionResult Create(Contact contact, FormCollection collection)
...
我用contact
对象捕获的常规字段以及那些需要在XmlFields
中存储为xml的字段我尝试用collection
捕获代码>对象。问题是 collection
对象捕获所有字段,所以我想知道在发布到特定对象时是否可以隔离 xml 字段,以便我可以轻松地操作它们。 我需要在单独的对象中使用它,因为这些 xml 字段将动态生成,并且对于每个用户来说都是不同的。
预先感谢,
岛
In database I have Contacts table:
ContactID (int)
FirstName (varchar)
LastName (varchar)
...
XmlFields (xml) // This field is xml type
To create a new contact, I created two classes - one for regular fields and other to display fields from XmlFields
field.
In Controller, I have following:
public ActionResult Create(Contact contact, FormCollection collection)
...
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以分隔字段,例如:
并将原始数据传递到 XML...MVC 没有任何自动方法可以知道将哪些数据推送到何处,除非您考虑创建自定义模型绑定器: http://davidhayden.com/blog/dave/archive/2008/09/08/ CustomModelBinderMoreUIValidationASPNETMVC.aspx 这是另一个有效选项。
HTH。
You can separate fields like:
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.
HTH.