进入页面时找不到任何解决方案以将另一个值作为默认值。这始终是我的第一价值。
创建“选择列表”
List<SelectListItem> list = new List<SelectListItem>();
var x = 0;
foreach (var lang in Enum.GetValues(typeof(ResourceHandler.Languages)))
{
list.Add(new SelectListItem { Selected = x == langInt, Value = x++.ToString(), Text = lang.ToString() });
}
视图模型:
public class SettingsViewModel
{
public int LanguageId { get; set; }
public List<SelectListItem> Language { get; set; }
}
看法:
@Html.DropDownListFor(x=>x.LanguageId, new SelectList(Model.Language,"Value","Text"))