Can you make an extension method that does the foreach for you?
Something like this:
public static class IEnumerableExtensions
{
public static string ToString<T>(this IEnumerable<T> collection, string separater)
{
if (collection == null)
return String.Empty;
return String.Join(separater, collection);
}
}
You could, of course, just call @String.Join(p.ArrayinXML, ", ")
in your code, but I think the extension method makes it a bit more elegant.
Then add the extension namespace to your web.config, and you can do this in the view:
@p.ArrayinXML.ToString(", ")
Edit:
Here's the extension with a transform parameter so you can customize further:
public static string ToString<T>(this IEnumerable<T> collection, string separater, Func<T, object> transform) where T : class
{
if (collection == null)
return String.Empty;
return String.Join(separater, collection.Select(s => transform(s).ToString()));
}