I'm having trouble wrestling with inserting spaces in commas in a foreach loop. Is there a better way to do this? It bother
@{ var multipleSpeakerSeparator = " "; }
@foreach (var speaker in session.SpeakersList)
{
@multipleSpeakerSeparator <a href="@(speaker.SpeakerLocalUrl)">
@speaker.UserFirstName @speaker.UserLastName </a>multipleSpeakerSeparator = ",";
}
Why not use String.Join:
I don't know if you can use @ syntax within String.Join, and how it would work, and how that would work with String.Join. Otherwise, using string concatenation as shown above would work.
If you are trying to inject a space, a space literal should render appropriately. I'm surprised it does not. Anyway, using the foreach approach, you should be able to do
@<text> </text>, and could conditionally do: