views:

1537

answers:

2

In ASP.NET MVC, how can I get a selected dropdown list value from a posted form?

+1  A: 
public class MyController
{
    public ActionResult MyAction (FormCollection form)
    {
        string value = form["DropDownListName"];
    }
}
User
+2  A: 
public class MyController
{
    public ActionResult MyAction(string DropDownListName)
    {

    }
}

This will do the line of code in MasterMind's answer for you. Which method you want to use depends on your situation. Either is fine in my opinion.

If all your possible selected values are numbers you can also do this:

public class MyController
{
    public ActionResult MyAction(int DropDownListName)
    {

    }
}

It will then convert the string of the selected value into an integer for you.

Garry Shutler