Check if ViewData is null before setting DropDownList to it

asp.net-mvc

Solution

You are not outputting anything and are incorrectly using the DropDownList helper. Try like this:

<% if (ViewData["roots"] != null) { %>
       <%= Html.DropDownList("roots") %>
<% } %>

Problem

I have this: ``` <% if (ViewData["roots"] != null) {%> <%Html.DropDownList("roots"); %> <%}%> ``` But it's not working. How to check if ViewData exists?

Original source