I just simply do this to get around that problem:
@model UXLab.Areas.SectionArea.ViewModels.SectionViewModel
<section>
<header>@Model.Title</header>
<p>
@{var contentBuilder = new System.Text.StringBuilder(); }
@foreach (var link in Model.Links)
{
contentBuilder.append(Html.ActionLink(link.LinkText, link.Action,
link.Controller));
}
@Html.Raw(contentBuilder.ToString())
</p>
</section>
In this example, I loop through some links I want to display to the page which are stored in a ViewModel.
In order to display the Links on the page, I loop through them all appending them to a StringBuilder, then use Html.Raw to display the raw Html, if you don't use Raw then you'll not get quotes and things through to the page example:
1: @String.Format("\"Hello {0}\"", Model.Name)
2: @Html.Raw(String.Format("\"Hello {0}\"", Model.Name))
Line 1 will display " Hello " Melman
Line 2 will display "Hello Melman"
Just some stuff I have found out when playing with outputting to the page. The basic idea is that, you build the page html up, then display it. So a store as you go method, once you finished manipulating the html output, you then display it using @ outsite of any {}