tags:

views:

79

answers:

1

I have an arraylist namelist in my model and in my view I need to fill the textarea with the values in 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?

A: 

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())) %>
Stephen Curran
with this, I am having a textarea for every value in the namelist, how can I solve this? <%foreach (string category in Model.namelist) {%> <%=Html.TextArea("name", Html.Encode(Model.namelist))%> <%} %>
Do you want to concatenate all strings in the list and display it in one textarea? Or do you want to display a textarea for each string?
Stephen Curran
concatenate all strings and display in one textarea, one string per line
I've added a little code sample.
Stephen Curran
Thanks, how can I change its height, I want it to display atleast 5 values?
You can do this through CSS. Here is a basic CSS tutorial http://www.w3schools.com/css/
Stephen Curran