c# - How can I bind an additional property to a DropdownListFor? -


in following code, id of selected country correctly passed controller when form submitted. however, i'd pass along name of country. how can send name along id controller?

model

public class mymodel {     public country country { get; set; }     public list<country> countrylist { get; set; } }  public class country {     public int? id { get; set; }     public string name { get; set; }     } 

view

@using (html.beginform()) {    <div>         @html.dropdownlistfor(m => m.country.id,         new selectlist(model.countrylist, "id", "name"))    </div>  } 

controller

mymodel model = new mymodel();  public actionresult index() {     using (var service = new service())     {         model.countrylist = service.getcountries();          return view(model);     } }  public actionresult index(mymodel tmpmodel) {    return redirecttoaction("index"); } 


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -