Matthew Nichols
Matthew Nichols

Reputation: 5035

How to pass an HtmlString as a Func<dynamic, HelperResult>

I am using Phil Haack's RenderSection helper to define layout Sections with default content. It all works nicely but in one case the default content is contained in an HtmlString. I had to wrap the variable expression in a span like this:

@this.RenderSection("aSectionName", 
   @<span>@anHtmlStringVariable</span> 
)

to get the Razor engine to interpret the HtmlString correctly. While it is unlikely that adding a span is going to cause problems for my layout it seems like I shouldn't have to wrap it like that. Is there a way around this?

Upvotes: 0

Views: 438

Answers (1)

Martin
Martin

Reputation: 8866

You can use <text>@anHtmlStringVariable</text>.

Upvotes: 1

Related Questions