Formatting strings in ASP.NET Razor
You need to create an IHtmlString
implementation holding your HTML source.
Razor plans to have a helper method to do this for you, but, AFAIK, it doesn't yet, so I believe you'll need to create your own class that implements the interface and returns your HTML from the GetHtmlString()
method.
EDIT: You can use the HtmlString
class.
You can either change your topHeader
dictionary to hold IHtmlString
s instead of String
s, or you can leave your code as is, but wrap it in an HtmlString
in the Razor view:
<tag>@new HtmlString(topHeader[x])</tag>
Make sure to correctly escape any non-HTML special characters.
SLaks is right, but you don't need to write your own implementation of IHtmlString
, there's one built in to System.Web
called HtmlString
. So:
topHeader[x] = new HtmlString("They think it's all over. <a title=\"Football News\" href=\"URL\">It is now!</a>");
Should do the trick.