简体   繁体   English

ASP.NET MVC 2 - 从下拉列表和列表框中检索选定的值

[英]ASP.NET MVC 2 - Retrieving the selected value from a dropdownlist and a listbox

I'm new to ASP.NET MVC and I'm using the example outlined in Steven Sanderson's book to create a multi-page, wizard like form for a web application. 我是ASP.NET MVC的新手,我正在使用Steven Sanderson的书中概述的示例为Web应用程序创建一个多页面的向导形式。

(See http://books.google.com/books?id=lfPkn31fpNQC&pg=PA477#v=onepage&q&f=false for the exact example). (有关确切示例,请参阅http://books.google.com/books?id=lfPkn31fpNQC&pg=PA477#v=onepage&q&f=false )。

I have it working to the point where I can persist data across pages, but I have no idea how to do this for a DropDownList control or a ListBox control. 我让它工作到我可以跨页面持久化数据,但我不知道如何为DropDownList控件或ListBox控件执行此操作。

Can anyone show me how to do this? 谁能告诉我怎么做?

Thanks. 谢谢。

Quite simply the dropdown list is an HTML select control, it's value will be in the form values posted to the action so if you set your form to post to an action then in the aciton you need: 相当简单的下拉列表是一个HTML选择控件,它的值将是发布到操作的表单值,因此如果您将表单设置为发布到操作,那么在您需要的aciton中:

public ActionResult RecieveForm(FormCollection values)
{
   var dropdownSelectedvalue = values["nameofdropdown"];
   ...
   work with result
   ...
   return View()
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM