4

I would like to post a form with a variable number of check-boxes, so in Model-biding i would receive an array or IEnumerable with each checkbox name and it's value.

What I pretend:

public class ItemsChecked{  
    public IEnumerable<string> Names{get; set;}  
    public IEnumerable<bool> Checked{get; set;}  
    //maybe organized in some other way
}

//In view  
@model IEnumerable<Tuple<string,bool>>

@foreach(var role in Model)
{  
<input name="@role.Item1" type="checkbox" checked="@role.Item2"/>
}

Is there any way to bind this to the ItemsChecked?

Bruno Costa
  • 324
  • 1
  • 5
  • 23

1 Answers1

1

This is a duplicate of ASP.NET MVC - Can't bind array to view model.

You can find a link there to Phil Haacks explanation on how to do it. Link is at http://haacked.com/archive/2008/10/23/model-binding-to-a-list.aspx

Community
  • 1
  • 1
photo_tom
  • 7,292
  • 14
  • 68
  • 116