In my model:
public SelectList QuestionGroupSelectList { get; set; }
------
List<QuestionGroup> questionGroupList = questionGroupRepository.GetQuestionGroup_BySurveyId(survey.Id);
Dictionary<int, string> questionGroupDictionary = questionGroupList.ToDictionary(l => l.Id, l => l.Name);
QuestionGroupSelectList = new SelectList(questionGroupDictionary, "key", "value", questionGroupId);
---------------------------------------
In view:
@Html.DropDownList("QuestionGroupSelectList", Model.QuestionGroupSelectList, "Choose Here")
When i debug i get 2 items in QuestionGroupSelectList (one with Id 30 and one with Id 35), and it says that the selectedValue is 35 (questionGroupId = 35)
But the selectedvalue does not work in the view, any ideas?
Thanks in advance!
You should use a different property to bind your dropdownlist value to. Also you should use view models and strongly typed helpers, like this:
then you could have a controller action which populates this view model and passes it to the view:
and finally in your view: