Click here to Skip to main content
15,908,455 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear All,
How can I Pass the Value from the View to Controller i.e.
I have a static Dropdown which I have created as follows.

1) Controller Code

C#
var list = new SelectList(new[] 
                {
                    new { ID = "1", Name = "name1" },
                    new { ID = "2", Name = "name2" },
                    new { ID = "3", Name = "name3" },
                },
                "ID", "Name", 1);

                ViewData["list"] = list;


2) In My View I am binding the Dropdown as follows:
@Html.DropDownList("list", ViewData["list"] as SelectList)

how can I get the selected value of the dropdown from view and pass it to a controller?

I tried the following but it did not work.
C#
string sTest = Request.Form["list"].ToString();


What I have tried:

string sTest = Request.Form["list"].ToString();
Posted
Updated 13-Mar-16 23:28pm

1 solution

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900