views:

27

answers:

2

I am very new to MVC and I have a Model like this

User :

FirstName : TextBox
LastName : TexBox
User Commitee : [CheckBox Textbox] [CheckBox Textbox] [CheckBox Textbox]

I store if user is in committee in a separate table.I need to insert selected check box value and related text box to database.How can I achieve this ? Can this be possible with using EditorTemplate ?

Thanks

A: 

Have a look at this answer here. It is the same as what you're looking for with the check boxes being bound to a child collection.

Steve Michelotti
Thanks Steve for quick reply.In my case I want to store value of Textbox next to checkbox if checkbox is selected .Textbox contains expiration date.In example above http://stackoverflow.com/questions/3938023/asp-net-mvc-many-to-many-model-on-client-side/3939407#3939407 it is just using checkbox right ?
George
You are correct. But the same technique still applies and will work for you. In the other example, there is a property bound to the checkbox. You simply need a property that you bind to the textbox as well.
Steve Michelotti
A: 

Thanks a lot Steve. So in this case will my model be something like this ?

public class Commitee {

public bool IsInCommitee { get; set; }
public int CommiteeId { get; set; }
public string CommiteeName { get; set; }

}

public class User{

public int Id {get;set;}
public string FirstName {get;set;}
public string LastName {get;set;}
public IEnumerable<Commitee> BelongsToCommitee {get;}

}

I am still not sure how would I populate BelongsToCommitee .

Mathew