It seems that you know that in order to make them work, it is necessary that the names for the switches are the same. However, when you do this in the editor template using the line of code @Html.RadioButton("SelectedItemId", Model.ItemId) , MVC 3 will take into account that you are in the editor template for elements and extra elements [n].
This will create a name like name="Items[0].SelectedIndex" . That would be nice if it weren't for the fact that the next switch would be `name =" Items [1] .SelectedIndex ".
One way to solve this problem is to not use the editor template and use the foreach instead. Here is the code I was able to get. I confirmed that model binding worked for SelectedIndex .
@model FormModel @{ ViewBag.Title = "Index"; } @using (Html.BeginForm()) { foreach (var item in Model.Items) { @Html.RadioButtonFor(x => x.SelectedItemId, item.ItemId) @item.ItemName <br/> @Html.TextBoxFor(m => item.ItemName) <br/> } <input type="submit" value = "submit" /> }
source share