0

I have a MVC3 app with the following model

public class Class1 
{
    public List<Class2> Class2Data { get; set; }
}

public class Class2
{
   public int Id { get; set; }
   public IEnumerable<Class3> Class3Data { get; set; }

}

public class Class3
{
    public int Id { get set; }
    public bool Selected { get; set; }
}

In my razor model

for (var i = 0; i < Model.Class2Data.Count();i++)
{
   @Html.HiddenFor(c => c.Class2Data[i].Id)

    foreach (var n in Model.Class2Data[i].Class3Data.ToList())
    {
          @Html.CheckBoxFor(x=> n.Selected);
          @Html.HiddenFor(x=> n.Id);
    }
}

However, when iam posting this to my controller, the Class3Data count is always 0 when I tick the checkboxes. Any ideas? Thanks

ninjaplayer
  • 65
  • 4
  • 13
  • possible duplicate of [View Model IEnumerable<> property is coming back null (not binding) from post method?](http://stackoverflow.com/questions/9915395/view-model-ienumerable-property-is-coming-back-null-not-binding-from-post-me) – rivarolle Sep 26 '13 at 16:03
  • Resolved by changing IEnumerable to List as wasnt binding properly – ninjaplayer Sep 27 '13 at 12:26

1 Answers1

0

Resolved by changing IEnumerable to List as wasn't binding properly

BenMorel
  • 34,448
  • 50
  • 182
  • 322
ninjaplayer
  • 65
  • 4
  • 13