c# - ASP MVC DropDownListFor Set Selected Value to Dictionary Value -


i have dropdownlistfor in markup:

@html.dropdownlistfor(     m => m.mydictionary[dictionarykey],     model.myselectlist selectlist); 

and dictionary property in view model:

public dictionary<keytypes, string> mydictionary { get; set; }  

myselectlist list of values, 1 through 5.

in controller, right before return view, set dictionary value:

_myviewmodel.mydictionary[dictionarykey] = "3" 

when page loads, selected value "1", not "3". however, if change dictionary string in view model , markup, dropdown has "3" selected on page load.

how bind dropdown dictionary value instead of string?

update

i made partial view own dynamically filled model. model contains following properties:

public string selectedvalue { get; set; } public myenum enumvalue { get; set; } public selectlist valuerange { get; set; } 

my partial view typed model, , contains dropdownlistfor:

@html.dropdownlistfor(     m => m.selectedvalue ,     model.valuerange selectlist) 

this seems work need. coming webforms, i'm not used breaking things quite much, starting make lot more sense. hope helps else :).


Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -