My web.config file has the following:
<p>
My text here...
</p>
Then in the controller I have:
ViewBag.terms = Properties.Settings.Default.TermsAndConditions;
Lastly, in the view I have:
@ViewBag.terms
What is being displayed on the webpage is literally the below, rather than the
tag being converted to HTML:
My text here...
Any idea how to turn the tags to HTML?
Solutions1
You shouldn't use the web.config to store HTML. Use a separate XML file.
E.g:
My text here...
]]>Wrapping the HTML in a CDATA section will ensure that you don't need to HTML encode the content before it's output.
@ViewBag.terms
Will HTML encode the terms value by default.
@Html.Raw(ViewBag.terms)
Talk1:
It was an unfortunate requirement of my project to have this in the web.config file. Using @Html.Raw() fixed the issue I was having. Cheers!
Solutions2
You've html encoded the data in the XML, so you need to decode it. You'll also need to use Html.Raw to output the HTML:
ViewBag.terms = HttpUtility.HtmlDecode(Properties.Settings.Default.TermsAndConditions);
@Html.Raw(ViewBag.terms)