IDI正在使用以下代码创建一个下拉列表:
@for (var index = 0; index < Model.AdminSummaries.Count(); index++) { <div class="rep_tr0"> <div class="rep_td0"> @Html.DropDownListFor(x => Model.AdminSummaries[index].Status,AdminStatusReference.GetAdminStatusOptions()) </div>
<select id="AdminSummaries_2__Status" name="AdminSummaries[2].Status"> <option value="1">Released</option> <option value="2">Review</option> <option value="3">New</option> </select> <select id="AdminSummaries_3__Status" name="AdminSummaries[3].Status"> <option value="1">Released</option> <option value="2">Review</option> <option value="3">New</option> </select>
有什么办法可以改变它,以便创建一个“Status_2”,“Status_3”等的ID。
解决方法
像@Anar在评论中说的;
Actually,you can change the name attribute the same way as id,but instead of “name”,use “Name”. Surprisingly it works.
@Html.DropDownListFor(x => Model.AdminSummaries[index].Status,AdminStatusReference.GetAdminStatusOptions(),new { id = string.Format("Status_{0}",index ),Name = "GiveName" });