获取DropdownList ID的值

时间:2015-03-17 11:06:06

标签: c# asp.net-mvc asp.net-mvc-4 razor dropdownlistfor

我有以下循环显示多个DropdownLists

             @for (int i = 0; i < Model.PositionAttribsMultiplierDef.Count; i++)
            {
                <tr>
                    <td>@Html.DisplayFor(x => Model.PositionAttribsMultiplierDef[i].PositionId)</td>
                    @for (int j = 0; j < Model.PositionAttribsMultiplierDef[i].AttribsByPosition.Count; j++)
                    {
                        <td>
                            @Html.DropDownListFor(m => m.AttribId, new SelectList(new[] { "0", "1", "2", "3", "4" },
                            Model.PositionAttribsMultiplierDef[i].AttribsByPosition[j].AttributePlayerPosMult.ToString()),
                             new { id = Model.PositionAttribsMultiplierDef[i].PositionId + "_" + 
                                 Model.PositionAttribsMultiplierDef[i].AttribsByPosition[j].AttributeId})
                        </td>
                    }
                </tr>
            }

我正在设法在模型中获取所选值:我在哪里: -

public string[] AttribId { get; set; }

现在我希望得到DropDownList的ID,这样我就可以将这个AttribID,例如“0”,或“1”,或“2”等附加到ID,这将类似于“CB_Cor”。

所以理想情况下我希望获得一个诸如“2_CB_Cor”之类的值,然后我可以解析该值并将其插入到数据库中。

所以我的问题是,如何附加此值

new { id = Model.PositionAttribsMultiplierDef[i].PositionId + "_" + 
                                 Model.PositionAttribsMultiplierDef[i].AttribsByPosition[j].AttributeId}

到m.AttribId

感谢您的帮助和时间!

0 个答案:

没有答案