开发者

Find value of selected item in Drop down menu

I have a drop down menu in an ASPX page along the lines of:

 <for开发者_运维知识库m>
 <select name="cars">
 <option value="volvo">Volvo</option>
 <option value="saab">Saab</option>
 <option value="fiat" selected="selected">Fiat</option>
 <option value="audi">Audi</option>
 </select>
 </form>

That is dynamically generated from another controller (value and label).

After the user selects one of the options I need to find out what the selected value/label (will be the same) is so I can hit an update button and retrieve the data on that option.

What would be the easiest way to find out the value of the user "selected" option?


Either use an <asp:dropdownlist /> control.

Just realised this MVC.

The simplest way would be to use the Request.Form collection, eg:

Request.Form["cars"]

Or you can specify them as properties on your controller:

public ActionResult ControllerMethod(string cars){...}

Or you can use model binders

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜