The constructor you are using looks like the following:
SelectList(IEnumerable, Object)
The second parameter here dictates the currently selected object from the collection in the first parameter. It does not dictate an object to use as a list of values.
What you should be doing is using SelectList(IEnumerable, String, String)
. This allows you to pass the name of a property (of each element of IEnumerable
) to use for the description and one for the value. You can then produce something like this:
Controller:
// Create your IEnumerable
var LoBs = new List<LoB>();
// Assign some parameters to your objects
var exampleItem = new LoB();
exampleItem.Description = "Option text";
exampleItem.Value = "myValue";
// Populate your list and return your view.
LoBs.Add(exampleItem);
ViewBag.LoBs = LoBs;
return View();
View:
@Html.DropDownList("Test",
new SelectList(ViewBag.LoBs, "Value", "Description"),
"--none--")
Et voila...
<select id="Test" name="Test">
<option value="">--none--</option>
<option value="myValue">Option text</option>
</select>