问题
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
回答1:
You can separate fields like:
public ActionResult Create(int ContactID, string FirstName)
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.
来源:https://stackoverflow.com/questions/2744054/asp-net-mvc2-specific-fields-in-form-pass-via-a-specific-object