asp.net mvc 4 - mvc4 bind @Html.DropDownListFor in controller -


how bind @html.dropdownlistfor value comes model? model:

public updatepersonalmodel() {   titles = new list<selectlistitem>();    titles.add(new selectlistitem{text = "mr",value = "mr"});   titles.add(new selectlistitem{text = "mrs",value = "mrs"});   titles.add(new selectlistitem{text = "miss",value = "miss"});   titles.add(new selectlistitem{text = "ms",value = "ms"});   titles.add(new selectlistitem{text = "dr",value = "dr"});   titles.add(new selectlistitem{text = "hon",value = "hon"});   titles.add(new selectlistitem{text = "prof",value = "prof"}); } public list<selectlistitem> titles { get; set; } public string title { get; set; } ... ... 

controller:

public actionresult updatepersonal() {     //...     var model = new updatepersonalmodel();     model.title = webcontext.currentuser.title;     model.firstname = webcontext.currentuser.first_name;     model.middlename = webcontext.currentuser.q_middle_name;     //...      return view(model); } 

in view: when have model.title brings model value duplicate value , not bind @html.dropdownlistfor(m => m.title, model.titles, model.title,new { @class = "enrtyfeildselect" }) here bring first value @html.dropdownlistfor(m => m.title, model.titles, new { @class = "enrtyfeildselect" })


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -