I use Visual Studio 2013 for a MVC website written in C# using JQuery.
I have two classes:
public class DetailModel
{
public bool isSelected { get; set; }
public int[] forSelect { get; set; }
}
public class MainModel
{
public DetailModel[] details { get; set; }
}
Main class includes an array of detail classes
I pass a MainModel to the View and in the view I have a table, every row of that table has two columns, first column has a checkbox and second column has a select. When I submit the form the controller must receive an array of structures with a) the checkbox b) an array of values selected in the SELECT but receives an array with the ONLY values of the first row.
I can't find a way to write correctly the view. I think is a bind problem.
@model MainModel
@foreach (DetailModel det in Model.details )
{
<input type="checkbox" name="???" value="@soa.id" />
<select multiple="multiple" name="???" >
}
In place of "???" (name) what should I write?
This is how the page as appears:
Edit 01: reading Stephen's link I made a step forward. Changing the code to this:
public class MainModel
{
public List<DetailModel> details { get; set; }
}
@for (int i = 0; i < Model.details.Count(); i++)
{
<input type="checkbox" name="details[@i].isSelected" />
<select multiple="multiple" name="details[@i].forSelect " >
}
now when I post the controller receives "something". Something is ALWAYS ONLY the values of first row. Nothing else: an array of structures with always only one element. Looking with F12 in the browser I see for the select names like details[0].forSelect, details1.forSelect, details[2].forSelect ...