Copied to clipboard

Flag this post as spam?

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


  • Ian Burrett 7 posts 71 karma points
    Aug 17, 2015 @ 10:30
    Ian Burrett
    0

    Passing macro parameters into Partial View Macro File

    Hi there,

    I'm using v7.2.8 and I'm trying to pass a node Id through to a macro partial that will then grab the content and pass it out as JSON.

    I cannot get the nodeId to be treated as a corrent Node and I end up having to hard code the id to get any text in JSON.

    What am I doing wrong.

    Template

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @{
        Layout = null;
    }
    @Umbraco.RenderMacro("flexibleJson", new {nodeId="1102"})
    

    Partial View Macro

    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    @using umbraco.NodeFactory
    
    @{  
        var macroNodeId = Model.MacroParameters["nodeId"];
        var termsAndConditionsNode = new Node(1102);
    
    
        var jsonToReturn = new {
             macroNodeId = macroNodeId,
             headerText = termsAndConditionsNode.GetProperty("pageHeader").Value,
             bodyText = termsAndConditionsNode.GetProperty("bodyText").Value
        };
    
        string json = Json.Encode(jsonToReturn);
        Response.ContentType = "application/json";
    }
    @Html.Raw(json)
    

    When I look at the rendered JSON the macroNodeId is coming through correctly as the specified 1102 - but there doesn't seem to be a way to get it to parse through as an actual node.

    I've tried .ToString(); converting to INT - etc.

    What am I missing?

  • Darren Clark 53 posts 250 karma points
    Aug 17, 2015 @ 14:29
    Darren Clark
    100

    Hi Ian,

    Try this below

     int macroNodeId = Convert.ToInt32(Model.MacroParameters["nodeId"].ToString());
     var termsAndConditionsNode = new Node(macroNodeId);
    

    Dazza

  • Ian Burrett 7 posts 71 karma points
    Aug 17, 2015 @ 14:42
    Ian Burrett
    1

    Once again Dazza you've shown me why I should stick to the CSS - I knew it would be a simple thing.

    Many thanks - another cold beer I owe you!

Please Sign in or register to post replies

Write your reply to:

Draft