我正在使用MVC4。
我在Index页面中添加了分页,排序和过滤功能。因此,我必须在过滤DropdownList中添加一个viewbag参数来保留过滤字符串。
这是一个带有viewbag参数的文本框示例:
@Html.TextBox("name",ViewBag.CurrentFilterName as string)
这很好用。
我想在DropDownList中添加一个viewbag参数。这是我的DropDownList的HTML代码:
@Html.DropDownList("type","All",ViewBag.CurrentFilterType as string).
这是错的。
有人能告诉我如何纠正它吗?非常感谢你!
可以想象他们可以:@Html.DropDownList("type", ViewBag.CurrentFilterType)
。
检查一下:MVC @Html.DropDownList Getting Error with SelectList in ViewBag
试试这段代码:查看:
@Html.DropDownList("Parameter", ViewBag.Parameter as SelectList)
</td>
controller:public ActionResult Index(){
ViewBag.Parameter = new SelectList(_dataModel.GetWeightage(), "Parameter");
return View();
}