.Net MVC动态单选按钮无法正确绑定

时间:2014-07-30 20:21:50

标签: asp.net-mvc

我有一种情况需要一双眼睛。我认为它与循环有关,但由于某种原因,无论选择哪个单选按钮,最后一个总是保存到db / populated。有什么想法吗?

@foreach (var l in collection.LineItems)
     {
                        var lIndex = collection.LineItems.IndexOf(l);
                        var ownerId = Model.Splits[collectionIndex].LineItems[lIndex].ownerId;
            var owners = new SelectList(Model.Owners.OrderBy(m => m.Text), "Value", "Text", ownerId);
                        var ownerName = string.Format("Splits[{0}].LineItems[{1}].ownerId", collectionIndex, lIndex);
                        var percentName = string.Format("Splits[{0}].LineItems[{1}].Percentage", collectionIndex, lIndex);
                        <tr class="split-l btn-group-parent">
                            @Html.HiddenFor(m => Model.Splits[collectionIndex].LineItems[lIndex].Id)
                            <input type="hidden" name="Splits[@collectionIndex].LineItems.Index" value="@lIndex" />
                            <td>
                                @Html.DropDownListFor(m => m.Splits[collectionIndex].LineItems[lIndex].ownerId, owners, "Select One" })

                            </td>
                            <td>
                                @Html.TextBoxFor(m => Model.Splits[collectionIndex].LineItems[lIndex].Percentage)%

                            </td>
                            <td>
                                @if (collection.PrimaryIndex == lIndex){
                                    <input name="Splits[@collectionIndex].PrimaryIndex" type="radio" value="@lIndex" checked="checked" />
                                } else {
                                    <input name="Splits[@collectionIndex].PrimaryIndex" type="radio"  value="@lIndex" />
                                }
                            </td>

0 个答案:

没有答案