@html.DropDownList關於它的使用

自渡,難渡。發表於2017-05-05
    var r = new List<Vendor>()
            {
                new Vendor() {VendorId = 1, Name = "a"},
                new Vendor() {VendorId = 2, Name = "b"},
                new Vendor() {VendorId = 3, Name = "c"},
                new Vendor() {VendorId = 4, Name = "d"},
                new Vendor() {VendorId = 5, Name = "e"},
            };
            //將Vendor的資料封裝到 SelectList中,制定要生成下拉框選項的value和text屬性  
            SelectList selList1 = new SelectList(r, "VendorId", "Name", 0);
            //把生成的集合放到ViewData中  
            ViewData["Categories"] = selList1;




@Html.DropDownList("myselect", (SelectList)ViewData["Categories"],  "--請選擇供應商--")
                                                   @* @Html.DropDownListFor(a => a.CategoryName, (SelectList)ViewData["Categories"], "--Select One--", new { @class = "dropdownlist" })*@

相關文章