In the constructor for SelectList
you can specify which fields are to be used for the text and for the value. This is done by passing string values to the constructor.
For example, if your GetSportsResult
object has a .ID
property as its identifier and a .Name
property as its display value, then your code would look like this:
var SportResultList = GetListOfSport();
var SportSelectList = new SelectList(SportResultList, "ID", "Name");
ViewBag.SportList = SportSelectList;
This would indicate to the SelectList
object that GetSportsResult.ID
should be the value for each item in the list, and GetSportsResult.Name
should be the displayed text for each item in the list.
Without specifying these fields, currently the object tries to make a "best guess" of what to display. It's probably doing this by calling .ToString()
on each object by default. And the default behavior of .ToString()
on a non-primative type is to display the name of the type itself, which is why you're seeing the string "GetSportsResult"
for each item.