How to display list of names present in viewdata in asp.net
I have a list of names in viewdata, but am not able to display it in view page
<body>
<%= ViewData["names"].T开发者_开发百科oString() %>
Thanks
If it's a list of strings, you have to iterate through it like so (I've put a div
there just to illustrate):
<% foreach (var name in (List<String>)ViewData["names"]) { %>
<div><%= name %></div>
<% } %>
You also must make sure that ViewData["names"]
is not null.
精彩评论