首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何在ViewBag中使用@Html.DropDownList?

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

Stack Overflow用户
提问于 2013-05-27 22:02:28
回答 2查看 8.5K关注 0票数 0

我和MVC4一起工作。

我已经添加了分页,排序和过滤功能的索引page.As的一个结果,我必须添加一个viewbag参数到过滤DropdownList来保持过滤字符串。

下面是一个带有viewbag参数的textbox示例:

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

这样做效果很好。

我想将viewbag参数添加到DropDownList。下面是我的DropDownList代码:

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

这是错误的。

有人能告诉我怎么改正吗?非常感谢!

EN

回答 2

Stack Overflow用户

发布于 2013-05-28 04:58:17

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

检查这个:MVC @Html.DropDownList Getting Error with SelectList in ViewBag

票数 0
EN

Stack Overflow用户

发布于 2014-12-05 18:29:03

尝试以下代码: View:

<td id="dropdown">
    @Html.DropDownList("Parameter", ViewBag.Parameter as SelectList)
</td>

控制器:

public ActionResult Index()
{
    ViewBag.Parameter = new SelectList(_dataModel.GetWeightage(), "Parameter");
    return View();
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16774905

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档