Binding a list belonging to another object in a custom model binder in ASP.NET MVC

Posted by Dan on Stack Overflow See other posts from Stack Overflow or by Dan
Published on 2010-03-12T01:26:06Z Indexed on 2010/03/12 1:27 UTC
Read the original article Hit count: 317

Filed under:
|
|

I realize something like this has been asked, but this may be a little different

Below is my Event object:

Event : IEvent
  public int Id
  public string Title
  public List<EventContact> Contacts

And EventContact:

EventContact
  public int Id
  public string Name

So, an Event has a list of EventContact' objects. Now, Event also implements IEvent - hence the custom model binder. I useIEventinstead of Event, so when the default model binder tries to do its thing, it lets me know it can't create anIEvent'.

I have my view with populated with the contact info:

<input type="text" name="contact[0].Name" value="DB Value"/>
<input type="text" name="contact[1].Name" value="DB Value"/>
<input type="text" name="contact[2].Name" value="DB Value"/>

<!-- Event fields, etc -->

So, in my custom model binder I am able to see all the value - sweet! The only thing is, I'm really not sure how to get all the contact fields and create a list of contacts from them, along with binding all the Event fields.

Any and all help is appreciated!

© Stack Overflow or respective owner

Related posts about c#

Related posts about asp.net-mvc