[RESOLVED]How to pass a selected value from dropdownlist present in view to controller

Hello ,

We are developing website which has a view where we want  to pass dropdownlist  selected value(id) from view to controller  and need to assign that id to session s .

We are using EF dbfirst. 

Hi

Have a name property set for the drop down field and you can use name as a parameter for the action under the controller.

<select name='offers'>
...
...
</select>

public ActionResult Read(string offers)
{ 
 // here you can access the selceted option value in offers variable.
}

 

Hi Pravalika,

                    Check the name of <Select name="selectListName"> tag and add parameter with the same name to your calling Action Method.

public class ControllerNameController : Controller
    {
        [HttpPost]
        public ActionResult ActionName(int selectListName)
        {
           // Now use selectListName as value field of selected item in DropdownList.
            return View();
        }
     }

Thanks,
Avishek

if It heps you pls mark as Answer.

Leave a Reply