I am using ASP.Net MVC4 (Razor). I have the following code:
Dictionary<string, OccasionObject> occasionList = new Dictionary<string, OccasionObject>()
The key is a string of the category of the occasion. The occassion object has 3 properties: isAttending(bool)
, ID(int)
, and Name(string)
In my cshtml file, I do the following:
@foreach(string s in model.occasionList .Keys)
{
foreach(var o in model.occasionList .Keys[s])
{
@Html.CheckBoxFor(m=>m.occasionList[s].FirstOrDefault(ev=>ev.ID == o.ID).isAttending);
}
}
This binds perfectly on the load, checking boxes that I have manually checked in SQL. However, when I POST this model back to the server, the occasionList dictionary is null. The model is binding fine because other properties I have in the model are still returned.
Any ideas?
Thanks, Dom