I have a table called Riders, containing information about horse riders. I want to use FirstName and 'ID' columns to populate a select dropdown. I've been bashing my head with this for a good 3 hours now and I get the same result - A dropdown list with same amount of options as my table recors, with text: System.Web.Mvc.SelectListItem. I pass the values to the View like this:
ViewBag.Riders = new SelectList(
db.Riders
.Select(r => new SelectListItem
{
Value = "test",
Text = "test"
})
.ToArray());
If I hover over ViewBag.Raiders while debugging I can see some system fields and then items, which contains my SelectList (full of "test") and Results View, which contains SelectList with Text values of System.Web.Mvc.SelectListItem. What is the problem here? Where did that Results View come from and why is it populated with SelectItem class name?
My Razor looks like this:
@Html.DropDownList("Riders", ViewBag.Raiders as SelectList)
I have tried using couple of different overloads of this DropDownList but to no success.
What am I doing wrong here? I thought accessing database with MVC is supposed to be easy. Its not intuitive for sure.