I have some "advanced" ViewModel I cannot handle properly. After posting the form there are keys in controller's action parameters, by values are nulls. I tried everything I found and everytime it had nulls, If you need more informations just write and I'll provide them.
I'm using jQuery's select2 plugin for my select inputs.
ParentViewModel:
public class ParentViewModel
{
public IList<string> ParentValues { get; set; }
public IDictionary<string, IList<ChildViewModel>> ChildDictionary { get; set; }
}
ChildViewModel:
public class ChildViewModel
{
public string Id { get; set; }
public IList<string> ChildValues { get; set; }
}
View:
@foreach (KeyValuePair<string, IList<ChildViewModel>> child in Model.ChildDictionary)
{
<table>
<thead>
<tr>
<td>Id</td>
<td>Values</td>
</tr>
</thead>
<tbody>
@for (var i = 0; i < child.Value.Count; i++)
{
<tr>
<td>@child.Value[i].Id</td>
<td>
@Html.HiddenFor(m => child.Value[i].Id)
// Here i tried manual binding
<select multiple="multiple" name="Model.ChildDictionary[@child.Key].Value[@i].ChildValues">
@for (var r = 0; r < Model.ParentValues.Count; r++)
{
<option @(child.Value[i].ChildValues.Contains(Model.ParentValues[r]) ? "selected" : "") value="@Model.ParentValues[r]">
@Model.ParentValues[r]
</option>
}
</select>
</td>
</tr>
}
</tbody>
</table>
}
EDIT:
Ok, if dictionary is bad, maybe you have an idea.
I got a List of that type of data:
ID | VALUES
Base1-subbase1-foo | foo, bar
Base1-subbase2-foo | foo
Base2-subbase1-foo | foo, bar
Base2-subbase2-foo | foo, bar
Base3-subbase1-foo | bar
and I need to group them by the "Base*" id value