I would recommend passing this via model. Also, I don't think you can use SelectList in MVC for DropDownListFor, i think you have to use a List of SelectListItem (or IEnumerable).
So the syntax for DropDownListFor can be something as simple as this
@Html.DropDownListFor(m=>m.Name, new List<SelectListItem>(), new{@class="form-control"})
m=>m.Name is the property name for your model and new List<selectlistitem> is your collection of items to display in the drop down. But notice, if you are not using a model in your view, you can't use DropDownListFor, instead, simply DropDownList will work as it is not strongly typed.
@Html.DropDownList("Name", new List<SelectListItem>(), new{@class="form-control"})
A more working example would be something similar to the following
Controller Action
public ActionResult Index()
{
var list = new List<People>();
list.Add(new People { Name = "David" });
list.Add(new People { Name = "Thom" });
var selectList = new List<SelectListItem>();
foreach (var item in list)
{
selectList.Add(new SelectListItem { Text = item.Name, Value = item.Name});
}
return View(selectList);
}
View - Index.cshtml
@model IEnumerable<SelectListItem>
@{
ViewBag.Title = "Home Page";
}
@Html.DropDownList("Name", Model, new{@class="form-control"})
But to use viewbag, you would do the same thing, but instead of model you just do
Controller
public ActionResult Index()
{
var list = new List<People>();
list.Add(new People { Name = "David" });
list.Add(new People { Name = "Thom" });
var selectList = new List<SelectListItem>();
foreach (var item in list)
{
selectList.Add(new SelectListItem { Text = item.Name, Value = item.Name});
}
ViewBag.Items = selectList;
return View();
}
@Html.DropDownList("Name", ViewBag.Items, new{@class="form-control"})