I have some issue with binding a collection to a model. I followed this link to create a list of checkbox. I am not sure of how much code to provide, but my view has the following models
Public class Model1{
public string param1{get; set;}
public string param2{get; set;}
}
Public class Model2{
public string param1{get; set;}
public string param2{get; set;}
}
Public class Model3: Model2{
public bool chk {get; set;}
public list<string> param{get; set;}
public Model3()
{
param = new List<string>(){"one", "two", "three"};
}
}
public class superModel{
public Model1 first{get; set;}
public IEnumerable<Model2> second{get; set;}
public List<Model3> third{get; set;}
}
In my controller, I have defined the parametr third as
third = AnEnumerableList.Select( e=> new Model3{chk=false, param1 = e.Param, param2 = e.Param1}).ToList();
and in my view, I pass the supermodel holding all my class model. I create a checkbox like this:
for(int i=0; i<Model.third.Count; i++){
@Html.CheckBoxFor(m => m.third[i].chk, new {onchange="test()"})
@Html.HiddenFor(m => m.third[i].param)
@Html.HiddenFor(m => m.third[i].param1)
@Html.HiddenFor(m => m.third[i].param2)
}
The javascript look like
function test(){
alert('@Model.third[0].chk')
}
When I look at the generated source code, everything looks fine, but the javascript code always returns false regardless of if the checkbox is checked or not. And when the view form is submitted, the whole view does not show. Instead, I get like a partial view with the name of the first selected checkbox. When nothing was selected in this collection, the returning view is submitted alright. I tried to debug the code, but nothing breaks during the process.
I know, this I may not have issolated this problem enough, but this is as much as I can...