开发者

How to display list of names present in viewdata in asp.net

开发者 https://www.devze.com 2023-03-12 21:15 出处:网络
I have a list of names in viewdata, but am not able to display it in view page <body> <%= ViewData[\"names\"].T开发者_开发百科oString() %>

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号