I want to create an empty dropdown list that has just default value.I use the following code:
@Html.DropDownList("parent","--Select Parent--")
But in running time I see this error:
There is no ViewData item of type 'IEnumerable' that has the key 'parent'.
How can I solve it? Thanks.
You can build an empty DropDownList like this:
@Html.DropDownList("parent", Enumerable.Empty<SelectListItem>(), "--Select Parent--")
Reference: Build an empty MVC DropdownListFor for a Cascade Sub-List
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With