List<SelectListItem> editlist= new List<SelectListItem>(){
new SelectListItem(){ Value="张三",Text="张三"},
new SelectListItem(){ Value="李四",Text="李四"},
new SelectListItem(){ Value="王五",Text="王五"},
};
@Html.LabelFor(a=> a.edit) @Html.ValidationMessageFor(a=> a.edit)
@Html.DropDownListFor(a=> a.edit, editlist, new { @class = "form-control" })
我想让下拉框随机绑定一个数据。
------解决思路----------------------
@{
Random rd = new Random(Guid.NewGuid().GetHashCode());
int v = rd.Next(editlist.Count);
Html.DropDownListFor(a=> a.edit, editlist.Select((item, i) =>
{
item.Selected = i == v;
return item;
}), new { @class = "form-control" })
}