[英]MVC4 DropDownList issue
So I'm building an MVC4 app, and I cannot get Html.DropDownList to behave at all. 所以我正在构建一个MVC4应用程序,我无法让Html.DropDownList完全表现。 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?
谁能指出我做错了什么?
You are missing an @
in front of the Html.DropDownList
你在
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! 如果没有
@
,你的代码只是评估一个MvcHtmlString
但它实际上并没有呈现给视图,那就是@
进来的地方!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.