简体   繁体   中英

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.

(See http://books.google.com/books?id=lfPkn31fpNQC&pg=PA477#v=onepage&q&f=false for the exact example).

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.

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:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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