When I am using @item.BodyText I am getting the raw html output – with html tags that are in it as strings. It looks like that:
<p>State of Louisiana for state funded dispensing program<br>June 21, 2011<br><br>Software update:<br>Version 3.1 is 10% faster<br>
And I need those html tags not to be presented as strings but to work and format text. So that it would look more like that:
State of Louisiana for state funded dispensing
program June 21, 2011Software update: Version 3.1 is 10% faster
I am using Umbraco 5 based on .Net Framework 4 and MVC3.
Code of my partial view:
@inherits RenderViewPage
@using Umbraco.Cms.Web;
@{
var Homepage = @DynamicModel;
while (Homepage.ContentType.Alias != "homePage")
{
Homepage = Homepage.Parent;
}
}
@foreach (var item in Homepage.Children)
{
if (@item.CurrentTemplate != null)
{
var childName = item.Name ?? "(No name yet)";
if (childName == "News")
{
@item.BodyText
}
}
}
I tried using @Umbraco.Field(Model, "bodyText") instead of @item.BodyText but then I got content of current page, and not “News” page that I need.
Any help much appreciated!
In Razor this happens for security reasons. All view output is Html encoded to prevent injections.
You always need to explicitly state that you don’t want Razor to HTML encode your raw output, you can do this by wrapping your statement with the
Html.Raw()helper method:Replace:
with: