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())) %>
精彩评论