c# - ASP.NET MVC Enumerable to delimited HTML in Razor -
this question has answer here:
i discovered can use string.join(", ", string[] enumerable)
turn list of strings single comma delimited string. similar produce example list of hyperlinks in razor view? instead of like:
@foreach(var item in enumerable) { <a href="@item.url">@item.title</a> if(item != enumerable.last()) { <span>, </span> } }
and if so, advisable or should stop being lazy?
@html.raw(string.join("<span>, </span>", enumerable.select(item => string.format("<a href=\"{0}\">{1}</a>", item.url, item.title))))
Comments
Post a Comment