Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Mam 5 posts 75 karma points
    Sep 14, 2015 @ 11:10
    Mam
    0

    Umbraco.StripHtml not removing all tags

    Hi there, I have an issue with StripHtml method. I use it fro my search results that need to display a few first characters of the page content. It seems to remove html for some records but not all. If the content is within only p tags it work but if I have strong, heading tags or list items, they are still displayed along with the p tags. Any suggestions how to get it to work and remove all html tags?

    Here's my partial view macro:

     @inherits Umbraco.Web.Macros.PartialViewMacroPage
    @using Examine
    @{var searchTerm = Request.QueryString["search"];}
    @{var searcher = ExamineManager.Instance.SearchProviderCollection["WebsiteSearcher"];}
    @{var results = searcher.Search(searchTerm, true).OrderByDescending(x => x.Score).TakeWhile(x => x.Score > 0.1f);}
    <div class="row searchHead">
        <div class="col-sm-12">
            <h2>Search results for:</h2>
            <h3 class="searchTerm">@searchTerm</h3>
        </div>
    </div>
    @{if (results.Count() == 0)
        {
            <div class="row">
                <ul class="searchList col-sm-12">
                    <p>Sorry, no results found</p>
                </ul>
            </div>
        }
        else
        {
            <div class="row">
                <div class="searchList col-sm-12">
                    @foreach (var result in results) 
                        {
                            <div class="searchItem">
                                @if(result.Fields.ContainsKey("pageTitle"))
                                    {
                                        <h3><a href="@umbraco.library.NiceUrl(result.Id)">@result.Fields["pageTitle"]</a></h3>
                                    }
                                else
                                    {
                                        <h3><a href="@umbraco.library.NiceUrl(result.Id)">@result.Fields["nodeName"]</a></h3>
                                    }
    
                                @if(result.Fields.ContainsKey("pageContent"))
                                    {
                                        @*var content = result.Fields["pageContent"];*@
                                        string content = result.Fields["pageContent"];
                                        if(content.Length >= 350)
                                            {
                                                @*<p>@content.Substring(0,350)...</p>*@
                                                @:<div>@Umbraco.StripHtml(@content.Substring(0,250))</div>
    
                                            }
                                        else
                                            {
                                                @*<p>@content</p>*@
                                                @:<div>@Umbraco.StripHtml(@content)</div>
                                            }
                                    }
                                else
                                {
                                    <p>No Summary</p>
                                }
                            </div>
                        }
                </div>
            </div>
        }
     }
    
  • Ross Ekberg 131 posts 382 karma points
    Feb 05, 2016 @ 16:23
    Ross Ekberg
    0

    I am having a similar issue where StripHtml isn't removing any or all html. I am using EZSearch.

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

    Continue discussion

Please Sign in or register to post replies