开发者

populate textarea from model arraylist

开发者 https://www.devze.com 2022-12-23 02:45 出处:网络
I have an arraylist namelist in my model and in my view I need to fill the textarea with the values in开发者_Go百科 the arraylist

I have an arraylist namelist in my model and in my view I need to fill the textarea with the values in开发者_Go百科 the arraylist

{%> 
   <%=Html.TextArea("Namelist",Html.Encode(namelist))%>
<%}

But i`m having the following in my textarea being dislpayed:

System.Collections.ArrayList...

How to solve this?


Html.Encode takes a single String parameter. Passing it an ArrayList is causing the ToString method to be invoked which is returning the name of the object type.

You need to iterate the collection, building the String and then pass that to Html.Encode.

Edit with code sample

<%
    StringBuilder sb = new StringBuilder();
    foreach (string category in namelist)
    {
        sb.Append(category + "\n");
    }
%>
<%= Html.TextArea("Namelist", Html.Encode(sb.ToString())) %>
0

精彩评论

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