如何在ViewBag中使用@ Html.DropDownList?

问题描述 投票:0回答:2

我正在使用MVC4。

我在Index页面中添加了分页,排序和过滤功能。因此,我必须在过滤DropdownList中添加一个viewbag参数来保留过滤字符串。

这是一个带有viewbag参数的文本框示例:

@Html.TextBox("name",ViewBag.CurrentFilterName as string) 

这很好用。

我想在DropDownList中添加一个viewbag参数。这是我的DropDownList的HTML代码:

@Html.DropDownList("type","All",ViewBag.CurrentFilterType as string).

这是错的。

有人能告诉我如何纠正它吗?非常感谢你!

asp.net-mvc filtering html-select viewbag
2个回答
0
投票

可以想象他们可以:@Html.DropDownList("type", ViewBag.CurrentFilterType)

检查一下:MVC @Html.DropDownList Getting Error with SelectList in ViewBag


0
投票

试试这段代码:查看:

                    @Html.DropDownList("Parameter", ViewBag.Parameter as SelectList)

                </td>

controller:public ActionResult Index(){

        ViewBag.Parameter = new SelectList(_dataModel.GetWeightage(), "Parameter");
        return View();
    }
© www.soinside.com 2019 - 2024. All rights reserved.