下拉选择框 设置内容 获取选中项 设置选中项
作者:互联网
设置内容
Html.DropDownList创建下拉框,下拉框名称为"useState",集合为ViewBag.UseStates,值是DicKey,显示是DicValue
使用状态 @Html.DropDownList("useState", new SelectList(ViewBag.UseStates, "DicKey", "DicValue")) @{ var UseState = ViewBag.UseState.ToString(); if (!string.IsNullOrEmpty(UseState)) { if (UseState.Contains("1")) {} else if (UseState.Contains("2")) {} else if (UseState.Contains("3")) {} } }获取选择项
public ActionResult DropDownList() { Listdic = new List(); dic.Add(new DictionaryModel() { PKID = 1, DicKey = "1Using", DicValue = "使用中" }); dic.Add(new DictionaryModel() { PKID = 2, DicKey = "2", DicValue = "未投入使用" }); dic.Add(new DictionaryModel() { PKID = 3, DicKey = "3", DicValue = "已废弃" }); ViewBag.UseStates = dic; ViewBag.UseState = 1; return View(); }
DictionaryModel
public class DictionaryModel { public int PKID { get; set; } public string DicKey { get; set; } public string DicValue { get; set; } }
标签:DicKey,ViewBag,DicValue,dic,获取,选中,设置,new,UseState 来源: https://blog.51cto.com/u_15180952/2733135