Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有这个:
<% if (ViewData["roots"] != null) {%> <%Html.DropDownList("roots"); %> <%}%>
但它不起作用。如何检查 ViewData 是否存在?
尝试
ViewData.ContainsKey("roots")
您没有输出任何内容,并且错误地使用了 DropDownList 帮助程序。试试这样:
<% if (ViewData["roots"] != null) { %> <%= Html.DropDownList("roots") %> <% } %>