views:

80

answers:

1

I have an ASP.Net-MVC app using LinqToSql. I have a subcontracts table, a service_lines table and a mapping/link table Service_lineToSubcontracts which contains the subcontract_id and service_line_id. On the subcontract view, I'd like to list the corresponding service lines.

This works, but has a trailing comma.

<% foreach (var sls in item.Service_lineToSubcontracts)
   { %>
   <%= Html.Encode(sls.service_line.service_line_name+", ") %>
<% } %>

I think I should be able to use something like String.Join(", ", item.Service_lineToSubcontracts.ToArray()) but I'm unsure of how to get the array of service_line_names.

+1  A: 

Do this:

<%= Html.Encode(string.Join(", ",
item.ServiceLineNames.Select(x=>x.service_line_name).ToArray())) %>
Keltex
Thank you. That led me in the right direction`<%= Html.Encode(string.Join(", ", item.Service_lineToSubcontracts.Select(x => x.service_line.service_line_name).ToArray())) %>`
RememberME
Great. I didn't quite understand how your classes were setup, so I did my best ;)
Keltex