Binding a list belonging to another object in a custom model binder in ASP.NET MVC
- by Dan
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!