I need to render a list of Person objects, say, in a comma delimited format using a Partial View in ASP.NET MVC. My problem is that when rendered using the following code:
<% foreach (var person in Model) { %>
<%= Html.ActionLink<PersonController>(c => c.Edit(person.PersonID), Html.Encode(person.Name)) %>,
<% } %>
I get a trailing comma after the last item. What's the most elegant/least stupid way to have this list of persons rendered without the last comma?
My two options so far, in no order, would be:
- Use JavaScript to remove the trailing comma on the client side
- Manually create the list using code, instead of markup, in the partial view
Neither of these options appeal to me - any ideas?
Thanks!