10

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

1
  • 1
    Check it here might help you. DropeDown List Commented Feb 3, 2011 at 14:31

2 Answers 2

6
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.

Sign up to request clarification or add additional context in comments.

1 Comment

thank you so much @Garry, wasted half day to get desired id from database list, at last this solution worked, for other options for binding databse table with dropdownlist check this, hope helps someone
4
public class MyController
{
    public ActionResult MyAction (FormCollection form)
    {
        string value = form["DropDownListName"];
    }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.