Can someone help me with getting values from a dropdownlist in asp.net mvc?
I can get values from textboxes,etc…but,how do I get these 2 things…
- Getting Selected Item Value of the drop down list from the controller class
- Getting all the list of items of the drop down list from the controller class
Thanks
You can get the selected value from a drop down list the same way as you do for text boxes.
Using default model binding
or from a FormCollection
or from the request
Where your drop down list is named “MyList”.
or straight HTML
The browser will only submit the selected value from the drop down list and not all the other values. To get the list of all the other items you should invoke the code that populated the list in the first place (assuming you used Html.DropDownList()).
Update