Copied to clipboard

Flag this post as spam?

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


  • Simon Goldsmith 14 posts 33 karma points
    Nov 21, 2013 @ 10:53
    Simon Goldsmith
    0

    partial view macro inheritance issue - what am I doing wrong??? :(

    I have the following code in a Partial View Macro file (HeroCarousel.cshtml).

    @*inherits Umbraco.Web.Macros.PartialViewMacroPage*@
    @inherits umbraco.MacroEngines.DynamicNodeContext
    @using The_Drum.App_Code
    @{
        if(Utilities.getXMLNode("HeroCarouselFolderID") != null)
        {
            //Get the id of the carousel images folder
            var carouselFolderID = Utilities.getXMLNode("HeroCarouselFolderID");
            //Get the media folder as a dynamic node
            var mediaFolder = Library.MediaById(carouselFolderID);
            if (mediaFolder.Children.Any())
            {
                //for each item in children of the selected media folder
                foreach (var mediaItem in mediaFolder.Children)
                {
                    <a href="#!" class="img"><img src="@mediaItem.umbracoFile"  alt="@mediaItem.Name"/></a>
    
                }
            }
        }
    
    }
    

    When I try and use in my template like so

    @Umbraco.RenderMacro("HeroCarousel")
    

    it errors:

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

    I think this is because the file needs to inherit from "Umbraco.Web.Macros.PartialViewMacroPage", but I need the methods and properties from "inherits umbraco.MacroEngines.DynamicNodeContext" - HOW DO I FIX THIS PLEASE?

  • Nikola Romcevic 26 posts 139 karma points
    Nov 21, 2013 @ 13:56
    Nikola Romcevic
    0

    I'm no pro, but have you tried @using umbraco.MacroEngines.DynamicNodeContext?

  • Charles Afford 1163 posts 1709 karma points
    Nov 25, 2013 @ 22:37
    Charles Afford
    0

    Hi what do you need from dynamic node context?  Can you not just instance a new dynamic node passing in the context id?

    Charlie :).

    If you remove all the code from your partial view.  Does it load correctly?  Charlie :)

Please Sign in or register to post replies

Write your reply to:

Draft