Copied to clipboard

Flag this post as spam?

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


  • Vilius Janulis 38 posts 79 karma points
    Feb 23, 2016 @ 18:22
    Vilius Janulis
    0

    Render macro from richtext editor inside partial view

    Hej,

    Umbraco v6.1.6.

    Basically have a solution where based on select via ajax I show partial view. In that partial view i am trying to render object property, that property is fetched via controller from some specific page - data type - rich text editor - using macros inside that rich text editor, and i cant make them to render properly.

    Simplified code:

    Partial view :

    @model namespace.ViewModels.PageModelSample
    <span>
        @Html.Raw(Model.Content)
        @*Html.Raw(umbraco.library.RenderMacroContent(Model.Content.ToString(), Model.PageId))*@
        @*Html.RichTextFor(m => m.Content)*@
        @*Umbraco.RenderMacro("Form")*@
    </span> 
    

    Controller :

    umbraco.NodeFactory.Node node = uQuery.GetNodesByName(NodeName).FirstOrDefault();
    
    // tried some manual regex conversions of current output to correct ones for rendering - kinda works but not always
    content = Helper.FixMacrosInContent(content, pageId);
    
    var PageModelSample = new PageModelSample()
    {
        ...
        Content = content,
        PageId = pageId
    };
    
    return PartialView(PageModelSample);
    

    Macro :

    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    @{
        var propertyX = Model.MacroParameters.FirstOrDefault(x=>x.Key == "SomeProperty").Value;
    }
    <a href="#"data-propertyX="@propertyX">here</a>
    

    On ajax load :

    Error loading Partial View script (file: ~/Views/MacroPartials/MacroX.cshtml) 
    

    So nothing really to difficult, but ... Tried all kind of render types and ways : Raw, RenderMacroContent and etc., nothing seems to work as it should. The problem is not that code itself - it is working ... i made it render both with RenderMacroContent and my custom regex function to parse content, but .. it still does not work as should.

    The problem : on ajax load it throws this partial view script error, but if i refresh the page - it works and everything is loaded as should.

    It works in editor rendering, it works after page refresh, cache turned off, everything published.

    Any ideas ? at least where i could continue looking :)

    Thanks.

Please Sign in or register to post replies

Write your reply to:

Draft