程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> C# >> 關於C# >> ASP.NET MVC3 DropDownList綁定問題

ASP.NET MVC3 DropDownList綁定問題

編輯:關於C#
 

如何使用Dictionary<int,string>綁定DropDownList問題,今天既然查了,就記錄下來分享給大家。

@{ 
    Dictionary<int, string> dictionaryTest = new Dictionary<int, string>()
    {
      {1, "Item n. 1"},
      {2, "Item n. 2"},
      {3, "Item n. 3"},
      {4, "Item n. 4"},
    };
    
    SelectList selectListFromDictionary = new SelectList(
        dictionaryTest.Select(x => new { value = x.Key, text = x.Value }),
        "value",
        "text"
    );
}
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved