how to remove html tags from rich text editor in Umbraco (Razor)
Solution 1
If the question is how to remove the paragraph tag which is rendered around the rich text, you may try the whether the following solution works for you:
@umbraco.library.RemoveFirstParagraphTag(page.product.ToString())
You may want to wrap that in a helper:
@helper RemoveParagraph(HtmlString s)
{
@Html.Raw(umbraco.library.RemoveFirstParagraphTag(s.ToString()))
}
and then call id like this:
@Helpers.RemoveParagraph(page.product)
Be aware though that umbraco.library.RemoveFirstParagraphTag
also removes line breaks (which most of the time is not a problem).
See also the Umbraco forum post about exactly this question: http://our.umbraco.org/forum/developers/razor/19379-Remove-paragraph-tags-with-razor
Solution 2
We ran into this same problem on one of our projects and solved it with this simple way of doing it. Wrapping the value with an "@Html.Raw()" fixed the issue.
<section class="links">
@{
var Link = Model.Content.Descendants("links");
<ul>
@foreach (var links in Link)
{
<li data-category="@(links.GetProperty("weblinkCategory").Value)">
<a href="@(links.GetProperty("weblinkAddress").Value)">
@(links.GetProperty("weblinkTitle").Value)
<span>@Html.Raw(links.GetProperty("weblinkDescription").Value)</span>
</a>
</li>
}
</ul>
}
Mr A
Web Developer Skills/Interest Learning new things daily ..Thats the beauty of programming :)
Updated on June 16, 2022Comments
-
Mr A almost 2 years
I am using a rich text editor to display description on the products page , but the page renders as :
<p>text description</p>
The macro for description is :
Razor syntax:
@foreach ( var page in @Model.Children) { <div id="productSection"> <div id="productstext"> <div id="image"> <a href="@page.Url"><img src="@page.productImage" height="200px" width="230px"/></a> </div> <div id="title"> <h3>@page.GetProperty("productTitle") </h3> </div> <div id="description"> @page.GetProperty("product") </div> </div> </div> }
Thnx in advance