I have a viewModel class ‘SomeDataViewMode’ that class have ‘List Schools’ object that is filled with ‘School’ objects. School obejct has properties SchoolID and Name.
In my view (Razor) I added:
@Html.DropDownListFor(c => c.ScoolId, new SelectList(Model.Schools), "Select some school")
But all I got is drop down list with:
MyProject.Domain.Entities.School
How to get values?
You should either add a
ToString()method to theSchoolclass, or use LINQ to createSelectListItems withTexts andValues:EDIT: Your code is needlessly complex.
You can write