下拉选择框 设置内容 获取选中项 设置选中项

设置内容
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()
{
    List dic = 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; }
}

你可能感兴趣的:(下拉选择框 设置内容 获取选中项 设置选中项)