动态地我应该加载下拉列表并显示选定的值。但成功加载下拉菜单,但未选择默认值。如何为DropDownListFor使用asp.net动态设置默认值mvc4
@ gt.PlantId - 整数, PlantId -integer
@foreach (var gt in Model.RoleList)
{
<tr>
<td>@Html.DropDownListFor(Model => Model.Plants,new SelectList(Model.Plants,"PlantId","PlantName", @gt.PlantId))</td>
<td>@gt.PlantId</td>
<td>@gt.RoleId</td>
@using (Ajax.BeginForm("deletedet", new AjaxOptions() { UpdateTargetId = "Edit-User", AllowCache = true, InsertionMode = InsertionMode.ReplaceWith }))
{
@Html.Hidden("userId", @gt.UserId)
<td><p data-placement="top" data-toggle="tooltip" title="Delete"><button class="btn btn-danger btn-xs" data-title="Delete" data-toggle="modal" data-target="#myTable"><span class="glyphicon glyphicon-trash"></span></button></p></td>
}
</tr>
}
'@ Html.DropDownListFor(M = >格雷尔,新塞尔lectList(Model.Genres,“Id”,“Name”),“DEFAULT VALUE GOES HERES”,new {@class =“form-control”})' – Unbreakable
请尝试上面的内容并做相应的更改。 “DEAFULT VALUE GOES GOES”将其替换为默认设置 – Unbreakable
Hi Unbreakable,非常感谢。根据价值我必须显示文本。当我输入“默认值GOES HERE”在这个我的ID我越来越像错误不能转换为字符串 – SENA