I have an event handler in my view which reacts on clicking an id. On clicking on the id, I call a method1 in my controller.
In the same view I have a dropdownlost which I fill with ViewData which is set in my method1.
But, since in the beginning, Index is called, and the ViewData is still empty, I get error that there is no such ViewData to fill my dropdown list.
How to set the dropdown list only if the Viewdata isn’t eppty?
You could test if you have values in ViewData before outputting the dropdown list:
or even better if you are using view models: