c# - How to bind key value pair to dropdown in MVC4 Razor -


i have country table "tblcountry", there 2 columns country name, country id, want display country name store country id in rest of tables. please tell me approach creating models view, using database first approach.

public partial class tblrfatcountry {     public long countryid { get; set; }     public string country { get; set; } } 

this model tried add dictionary.

public partial class tblrfatcountry {     public long countryid { get; set; }     public string country { get; set; }     public dictionary<string, long> countrydic = new dictionary<string, long>(); }  

i want can display name store value. please suggest

you need :

@{      dictionary<long, string> dictionarycountry = new dictionary<long, string>()     {       {1, "item1"},       {2, "item2"},       {3, "item3"},       {4, "item4"},     };         selectlist countrylist= new selectlist(             dictionarycountry.select(x => new { value = x.key, text = x.value }),             "value",             "text"         );  }  @html.dropdownlist("ddlcounry", countrylist) 

you can refer here more details


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -