zoukankan      html  css  js  c++  java
  • Html.DropDownList()的用法 ( Asp.Net MVC)

    Html.DropDownList()赋默认值:

    页面代码如下:

      <%
                    List<SelectListItem> list = new List<SelectListItem> {

                    new SelectListItem { Text = "启用", Value = "0",Selected = true},

                    new SelectListItem { Text = "禁用", Value = "1" } };
      %>//list储存dropdownlist的默认值
     <%=Html.DropDownList("state",list,Model.state) %>  //state为实体的属性,默认选中"启用"

    Html.DropDownList()从数据库读取值:

    页面代码如下:

    <%= Html.DropDownList("Category", ViewData["Categories"] as SelectList,"--请选择--",new { @class = "my-select-css-class" } )%>

    Controllers代码:

    public ActionResult Create() 

    {
            List<Category> categories = categoryService.GetAll();
            ViewData["Categories"] = new SelectList(categories, "Id", "Name");
            return View();
    }

  • 相关阅读:
    求一个数字各个位的数字之和
    二进制和十进制的转换 分别用python和js实现
    pymysql 获取插入数据的主键id
    js03.事件
    02.js运算符
    jsonpath
    01.js控制台
    2.命令补充
    hashmap
    正则表达式的补充
  • 原文地址:https://www.cnblogs.com/gengaixue/p/2078256.html
Copyright © 2011-2022 走看看