如何在下拉列表中获取所选项目的ID? [英] How to get id of selected Item in dropdownlist?

查看:99
本文介绍了如何在下拉列表中获取所选项目的ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在MVC中获取所选的DDL Id我没有使用Html助手生成Dropdownlist但是简单< select>< / select>



 Id = Request.Form [  ddl1]。ToString(); 



这对我不起作用。我正在尝试从View中获取Id并传递相同视图的ID具有另一个下拉列表



  foreach (系统。 Data.DataRow dr  in  Class.Getddl2(Id).Rows)





Getddl2是我班上的一个方法,我将 Id 传递给ddl。



整个代码在View中,而不是在控制器中或者类。



请注意我在使用Ajax重新加载页面时请求ID。

解决方案

< blockquote> Ids不与表单数据一起提交,因此您无法获得服务器端,只有名称和值可用。如果你想要id,你需要找到一些方法将它传递给隐藏的字段或其他东西。


I want to get the selected Id of DDL in MVC i am not using Html helpers to generate Dropdownlist but simple <select></select>

Id = Request.Form["ddl1"].ToString();


It is not working for me.I am trying to get the Id from View and passing the Id to same View having another Dropdownlist

foreach (System.Data.DataRow dr in Class.Getddl2(Id).Rows)



Getddl2 is a method in my class and i am passing that Id to ddl.

This whole code is in View and not in controller or Class.

please note that i am requesting the Id when i reload the page using Ajax.

解决方案

Ids are not submitted with the form data so you can't get them server-side, only the name and value are available. If you want the id you'll need to find some way of passing it in a hidden field or something.


这篇关于如何在下拉列表中获取所选项目的ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆