Reputation: 920
So I'm building an MVC4 app, and I cannot get Html.DropDownList to behave at all. All the actual page is showing is a submit button, and it doesn't actually render the drop down list.
This is the controller:
public ActionResult Index() {
var items = new SelectList(
new[] {
new { Value="ships", Text="Ship" },
},
"Value", "Text"
);
ViewData["tableitems"] = items;
return View();
}
And this is the view:
@using (Html.BeginForm("Search", "Encyclopedia", FormMethod.Get)) {
@*<select id="table" name="table">
<option value=""></option>
<option value="ships">Ship</option>
</select>*@
Html.DropDownList("table", ViewData["tableitems"] as SelectList, "Ship" );
<input type="submit" value="view" />
}
I've been searching online for hours trying various permutations, but I can't get it. Can anyone point out what I'm doing wrong?
Upvotes: 1
Views: 720
Reputation: 14944
You are missing an @
in front of the Html.DropDownList
@using (Html.BeginForm("Search", "Encyclopedia", FormMethod.Get)) {
@Html.DropDownList("table", ViewData["tableitems"] as SelectList, "Ship" );
<input type="submit" value="view" />
}
Without the @
, your code is just evaluating to an MvcHtmlString
but it's not actually being rendered to the view, that's where the @
comes in!
Upvotes: 3