你的位置:首页 > ASP.net教程

[ASP.net教程]MVC 下拉單數據內容綁定


 #region
        /// <summary>授權範圍自建列表</summary>
        /// <returns></returns>
        public static List<SelectListItem> GetBookSourceSelectList()
        {
            List<SelectListItem> BookSourceSelectList = new List<SelectListItem>();
            BookSourceSelectList.Add(new SelectListItem() { Value = "1", Text = "雄獅旅遊" });
            BookSourceSelectList.Add(new SelectListItem() { Value = "2", Text = "雄獅資訊" });
            BookSourceSelectList.Add(new SelectListItem() { Value = "3", Text = "雄獅通運" });
            BookSourceSelectList.Add(new SelectListItem() { Value = "4", Text = "雄獅杏林事業" });
            BookSourceSelectList.Add(new SelectListItem() { Value = "5", Text = "欣傳媒" });
            BookSourceSelectList.Add(new SelectListItem() { Value = "6", Text = "傑森全球整合行銷" });
            BookSourceSelectList.Add(new SelectListItem() { Value = "7", Text = "雙獅聯合" });
            BookSourceSelectList.Add(new SelectListItem() { Value = "8", Text = "欣聯航" });
            BookSourceSelectList.Add(new SelectListItem() { Value = "9", Text = "其他" });
            return BookSourceSelectList;
        }
        #endregion

 

前台調用方法:

@Html.DropDownListFor(m => m.Book.BookAuditorSource, Model.BookSourceList, "請選擇", new { id = "sel_BookSource", @class = "input-medium", onchange = "GetBookAuditorName()" })