Working on MVC 5 app with EF 6. I am loading a dropdownlistfor but the default selected value is not working properly. Any ideas why?
Here's part of my ViewModel...
public class ToolQuestionViewModelEdit
{
public ToolQuestion ToolQuestion { get; set; }
public SelectList ToolQuestionCategoryList { get; set; }
public int SelectedToolQuestionCategory { get; set; }
}
Here is my controller code to fill the select list...
vm.ToolQuestionCategoryList = new SelectList(
this.db.ToolQuestionCategories,
"Id",
"ToolQuestionCategory1",
ToolQuestion.ToolQuestionCategoryId);
Here's my razor code...
@Html.DropDownListFor(c => c.SelectedToolQuestionCategory,
Model.ToolQuestionCategoryList as SelectList,
new { @class = "form-control" })
In the immediate window, when I debug my code I see the that the selected value is working properly...
? vm.AuditQuestionCategoryList.SelectedValue
82
82 is the proper value that should be selected. But, the view always defaults to the first item. The dropdown is properly displayed with the correct items so I know it's reading the viewmodel properly.
Any ideas? Seems like I'm doing this write.