Copied to clipboard

Flag this post as spam?

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


  • Elliott Brown 40 posts 210 karma points
    Jul 29, 2019 @ 09:50
    Elliott Brown
    0

    Help! 'Cannot render a macro when there is no current PublishedContentRequest.'

    The short story is I have a list of blog articles which I'm casting to a model which contains .wordCount. This is calculated by striping the HTML from the output of the RTE and then calculating the lengh. The output of the RTE can contain Macros.

    On first load, i.e from a view, I have no problems. However, when I refresh my list articles using a clientside AJAX call I get an exception on function to strip the HTML from the output of the RTE. The error I get is System.InvalidOperationException: 'Cannot render a macro when there is no current PublishedContentRequest.'I have included a snippet of my code below. I suspect this is something simple and to do with how my IPublishedContent is treated when called from AJAX opose to complied in the view.

    My Code

    public static Article ToArticle(this IPublishedContent item)
    {
        string rawText = HelperFunctions.StripHTML(item.GetPropertyValue<string>("richText"));
        ...
    }
    
    public static string StripHTML(string htmlString)
    {
        string pattern = @"<(.|\n)*?>";
        return Regex.Replace(htmlString, pattern, string.Empty);
    }
    

    Thanks in advanace

Please Sign in or register to post replies

Write your reply to:

Draft