I've seen a number of examples where the create and edit action methods are bound to a single object as such:
public ActionResult Create (Person person) {}
with view code like Html.Textbox(person.Name, ViewData.Model.Name)
***
I was wondering if it is possible to bind to multiple objects ... something like:
public ActionResult Create (Person person, ContactInfo, contactInfo) {}
with view code like Html.Textbox(person.Name, ViewData.Model.Name) and Html.Textbox(contactInfo.Address1, ViewData.Model.Contact.Address1)
***
Or even better, is it possible to bind a collection of another object ... something like:
public ActionResult Create (Person person, ContactInfo[], contactInfo) {}
with view code like Html.Textbox(person.Name, ViewData.Model.Name) and Html.Textbox(contactInfo.Address1, ViewData.Model.Contacts[0].Address1) and Html.Textbox(contactInfo.Address1, ViewData.Model.Contacts[1].Address1)
So is this even possible? If so, any suggested practices and/or examples out there I could take a look at? Any ideas would be much appreciated!
wgpubs
Member
15 Points
12 Posts
Bind to multiple objects?
Nov 22, 2008 03:10 AM|LINK
Hi Folks,
I've seen a number of examples where the create and edit action methods are bound to a single object as such:
public ActionResult Create (Person person) {}
with view code like Html.Textbox(person.Name, ViewData.Model.Name)
***
I was wondering if it is possible to bind to multiple objects ... something like:
public ActionResult Create (Person person, ContactInfo, contactInfo) {}
with view code like Html.Textbox(person.Name, ViewData.Model.Name) and Html.Textbox(contactInfo.Address1, ViewData.Model.Contact.Address1)
***
Or even better, is it possible to bind a collection of another object ... something like:
public ActionResult Create (Person person, ContactInfo[], contactInfo) {}
with view code like Html.Textbox(person.Name, ViewData.Model.Name) and Html.Textbox(contactInfo.Address1, ViewData.Model.Contacts[0].Address1) and Html.Textbox(contactInfo.Address1, ViewData.Model.Contacts[1].Address1)
So is this even possible? If so, any suggested practices and/or examples out there I could take a look at? Any ideas would be much appreciated!
Thanks - wayde