I want to make the list like this: "1, 2, 3"
Quick and dirty:
@string.Join(", ", Enumerable.Range(1, 3))
Obviously, the user assistant is more suitable for setting the formatting of something in the view:
public static class HtmlExtensions
{
public static IHtmlString FormatList(this HtmlHelper html, IEnumerable<int> list)
{
return MvcHtmlString.Create(string.Join(", ", list));
}
}
and then just:
@Html.FormatList(Model.MyList)
source
share