Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/261.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# MVC4下拉列表问题_C#_Asp.net_Asp.net Mvc 4 - Fatal编程技术网

C# MVC4下拉列表问题

C# MVC4下拉列表问题,c#,asp.net,asp.net-mvc-4,C#,Asp.net,Asp.net Mvc 4,因此,我正在构建一个MVC4应用程序,而我根本无法让Html.DropDownList正常工作。所有实际显示的页面都是一个提交按钮,它实际上并不呈现下拉列表 这是控制器: public ActionResult Index() { var items = new SelectList( new[] { new { Value="ships", Text="Ship" }, },

因此,我正在构建一个MVC4应用程序,而我根本无法让Html.DropDownList正常工作。所有实际显示的页面都是一个提交按钮,它实际上并不呈现下拉列表

这是控制器:

    public ActionResult Index() {
        var items = new SelectList(
            new[] {
                new { Value="ships", Text="Ship" },
            },
            "Value", "Text"
        );

        ViewData["tableitems"] = items;

        return 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" />
}
@使用(Html.BeginForm(“搜索”、“百科全书”、FormMethod.Get)){
@*
船
*@
Html.DropDownList(“table”,ViewData[“tableitems”]作为SelectList,“Ship”);
}

我在网上搜索了好几个小时,尝试了各种排列方式,但我找不到。有人能指出我做错了什么吗?

您在
Html.DropDownList
前面缺少了一个
@

@using (Html.BeginForm("Search", "Encyclopedia", FormMethod.Get)) {
    @Html.DropDownList("table", ViewData["tableitems"] as SelectList, "Ship" );
    <input type="submit" value="view" />
}
@使用(Html.BeginForm(“搜索”、“百科全书”、FormMethod.Get)){
@Html.DropDownList(“table”,ViewData[“tableitems”]作为SelectList,“Ship”);
}

没有
@
,您的代码只是计算为
MvcHtmlString
,但它实际上没有呈现到视图中,这就是
@
的作用所在

你看到这个了吗?那是我正在看的一页,但我还是想不出来。