san
san

Reputation: 1859

Get dropdown list value in MVC3 Razor

Please help me to get the selected value of the dropdown list in the controller when i am clicking the submit button.

        My view is like
         @using (Html.BeginForm())
         {
            @foreach (var department in @Model)
            {
             items.Add(new SelectListItem
             {
                 Text = @department.DeptName,
                 Value = @department.DeptId.ToString()
             });                               

            }           
            @Html.DropDownList("deptID", items, "--Select One--", new { @style = width:160px" })                                               *              
            <input type="submit"   name="Filter" value="filter"  />
        }

    Please share if you are having any website link which explains about the dropdown list and its events in mvc3 Razor.

Thanks San

Upvotes: 1

Views: 14650

Answers (1)

fearofawhackplanet
fearofawhackplanet

Reputation: 53378

MVC deals with the binding for you if you have a parameter with the same name

public ActionResult MyAction(string deptID) 
{
    // whatever
}

Upvotes: 3

Related Questions