如何获取Dropdownlist选中的值
如何从 CSHTML 页面获取 dropdownList 选定的项目。
<div class="editor-field">
@Html.DropDownList("ROUTE_GROUP_ID", String.Empty)
@Html.ValidationMessageFor(model => model.ROUTE_GROUP_ID)
</div>
How to get dropdownList selected Item from CSHTML page.
<div class="editor-field">
@Html.DropDownList("ROUTE_GROUP_ID", String.Empty)
@Html.ValidationMessageFor(model => model.ROUTE_GROUP_ID)
</div>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果你想要它在 jquery 中的值,你可以这样做
,或者如果你想要它在控制器中的值,你可以访问它,
或者如果你的控制器有一个 formcollection 对象,那么访问该值,例如
If you want its value in jquery you can do like this
or if you want its value in controller you can access it from
or if your controller have a formcollection object then access the value like
从您的示例中,我看不出您将如何获取任何选定的值,因为您尚未定义 DropDownList 从中获取其值的 SelectList。
我建议您创建一个 ViewModel,用您的 RouteGroup 填充 SelectItemList,并将其 ID 作为值传递。像这样:
在您的视图上:
在您的控制器上:
这样您就可以获得 DropDownList 选定的值。
From your example, i don't see how you would get any selected value, since you haven't defined the SelectList from which your DropDownList will get it's values.
I'd suggest you to create a ViewModel, fill a SelectItemList with your RouteGroup, passing it's ID as value. Like this:
On your view:
And on your Controller:
With that you can get the DropDownList selected value.