Search code examples
razorumbracoumbraco-blog

how to remove html tags from rich text editor in Umbraco (Razor)


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


Solution

  • 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