html5 - Dropdownlist using viewbag data in mvc4 using c# -


hi want fill dropdown list in view page code is

public class memberbasicdata {     public int id { get; set; }     public string mem_na { get; set; }     public string mem_occ { get; set; } } 

//controller

  public actionresult register()     {         var users = new member().getallmembers();         viewbag.users = users;            return view();     } 

//view

 @model ienumerable<....members.models.memberbasicdata>  @html.dropdownlistfor(model => model.mem_na, (selectlist)viewbag.users, "--select users--") 

i want add mem_na dropdownlist, viewbag contains user details. problem in view page. error shows in model.mem_na. please me solve this.

please, change code

from

@model ienumerable<....members.models.memberbasicdata> @html.dropdownlistfor(model => model.mem_na, (selectlist)viewbag.users, "--select users--") 

to

@model ....members.models.memberbasicdata @html.dropdownlistfor(model => model.id,new selectlist(viewbag.users,"id","mem_na"), "--select users--") 

it works me everytime


Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -