So if Set up a DropDownList where Text: "people names" (string)and Value:studentID (int). in my view like this (assuming myDDL is data from code-behind placed in the viewbag)
@Html.DropDownList("myDDL", (IEnumerable<SelectListItem>)ViewBag.myDDL,
"Select Stuff", new Dictionary<string,object>{
{"class","dropdowns"},{"id","myDDL"}})
What is the value of “Select Stuff” which is an optional label that appears at the beginning of the dropdown list?
I’d like the value because it if no value is selected then I’d like to get all the data.
Thanks!
It’s empty and it’s always the first option of the dropdown, so make sure that you are binding it to a non-nullable property in the postback action:
Also you seem to be using
myDDLas both the first argument and the second of the dropdownlist helper which is wrong. The first argument is a property that would be used to get the selected value. The second is the available values and must be anIEnumerable<SelectListItem>.So something like this would make more sense:
But what would really make sense and what I would recommend you is to get rid of this
ViewBagand use a view model and the strongly typed version of this helper: