Copied to clipboard

Flag this post as spam?

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


  • Patompol Taesuji 17 posts 39 karma points
    May 10, 2013 @ 14:15
    Patompol Taesuji
    0

    Umbraco 6.1 How to get macro parameter in partial view macro

    I'm a newbie for implement partial view macro in Umbraco 6.1. I create a macro name: DisplayContent and havea pararmeter call PageId

    I put this macro on template like this

    @Umbraco.RenderMacro("DisplayContent", new {PageId="1234" })

    and then in partial view macro,I try to use   @Model.MacroParameters for show that parameter

    but I can't use this method for get that parameter. 

    How should I do? please suggestion

    PT

  • Charles Afford 1163 posts 1709 karma points
    May 10, 2013 @ 14:29
  • Patompol Taesuji 17 posts 39 karma points
    May 11, 2013 @ 17:04
    Patompol Taesuji
    0

    @Charles, Thank you for your suggestion. Normally, I did with XSLT like

    <xsl:variable name="getPageIdFromMacro"select="/macro/PageId"/>

    or Can I get value from Xslt?

    Any idea for get macro parameter in parital view?

  • Charles Afford 1163 posts 1709 karma points
    May 11, 2013 @ 18:15
    Charles Afford
    0

    Hi Patompol, if you are using razor you wont be able to use XSLT.  What data are you trying to access in which location?  Thanks.  Charlie :)

  • Patompol Taesuji 17 posts 39 karma points
    May 12, 2013 @ 12:04
    Patompol Taesuji
    0

    Hi Charlie, sorry if I made you confuse my problem.

    step 1: I create partial view macro and add parameter property.

    step 2: I put that macro in tempate and set value to parameter.

    step 3: I would like to get value of parameter in partial view macro. but I can use @Model.Macroname, @Model.MacroAlias but I can't use @Model.MacroParameters

    Thanks for your reply.



     

  • Charles Afford 1163 posts 1709 karma points
    May 12, 2013 @ 12:13
    Charles Afford
    0

    Hi, are you using razor?  and what data are you trying to pass in as a parameter?  I am just wondering if there is a better way of getting this information :).  Charlie

  • Patompol Taesuji 17 posts 39 karma points
    May 12, 2013 @ 12:40
    Patompol Taesuji
    0

    Yes, I'm using razor for implement. I create content picker as macro parameter for choosing a content node in the content section. so I have to get node Id (int) of the page.

    when I had node Id, I can get some details of that Node

    example: nodeName, create by, NiceUrl or some properties

    Node node = new Node(node Id);

     

     

     

     

     

  • Fuji Kusaka 2203 posts 4220 karma points
    May 12, 2013 @ 14:08
    Fuji Kusaka
    0

    Hi ,

    If you are using razor you could try this instead

                   var p= @Parameter.source;
                  var c= Model.NodeById(@p);

    Hope this helps

    //fuji

  • Patompol Taesuji 17 posts 39 karma points
    May 12, 2013 @ 19:34
    Patompol Taesuji
    0

    @Fuji, Thanks for your help. but I think that is syntax of Umbraco 5. I can't use on partial view macro in Umbraco 6.1

    Perhaps, I forgot define @using .....  at the head of the partial view. if I wrong, please explain more to me. :))

  • Fuji Kusaka 2203 posts 4220 karma points
    May 12, 2013 @ 19:49
    Fuji Kusaka
    0

    Hi Patompol,

    I myself am not very used to Partial Views but if you are only using razor this should work and add

    @using umbraco.MacroEngines 
    @{
    ///
    }
  • Patompol Taesuji 17 posts 39 karma points
    May 13, 2013 @ 05:08
    Patompol Taesuji
    2

     This morning, I can found the syntax for get value from Macro parameter

    @using umbraco.MacroEngines
     var getParameterFromTheMacro =   Model.MacroParameters;
     string getPageId = getParameterFromTheMacro.SingleOrDefault(x => x.Key == "PageId").Value.ToString();
    @getPageId 

    Thank you everyone,

    PT

        

  • Charles Afford 1163 posts 1709 karma points
    May 13, 2013 @ 10:00
    Charles Afford
    0

    Hi, sorry for the late reply.  Why can you not just get the id out of @model or instance a new node and get the property in your .cshmtl View/PartialView??  May be i am missing something?  Why do you need a macro parameter?  Charlie :)

    Glad you got it fixed though

  • Patompol Taesuji 17 posts 39 karma points
    May 13, 2013 @ 13:51
    Patompol Taesuji
    0

    I would like macro because

    1. I can insert macro at anywhere 

    ex: richtext editor, template, patial view and partial view macro

    2. I can choose any nodes, if I would like.

    ex: I made the advertisment collections and have many advertisment item nodes under the collection hierachy, I can use macro for choose only root node of the collection after that I can display all of them.

    3. In patial view, we can pass some parameter to another patial view by using macro parameter.

     

    PT

  • Charles Afford 1163 posts 1709 karma points
    May 13, 2013 @ 21:35
    Charles Afford
    0

    Ah ok that makes sense :).  Thanks,

  • Francisco 21 posts 72 karma points
    May 14, 2013 @ 04:04
    Francisco
    0

    I'm trying to get parameters on Macro Partial Views too.

    The only way to access is using Model.MacroParameters dictionary? It seems a little bit nasty.

    Would be nice having some extension method helpers to retrieve parameters.

    Whatever, thank you for code Patompol!

     

  • Stefan Arngrimsson 36 posts 59 karma points
    May 31, 2013 @ 00:55
    Stefan Arngrimsson
    3

    Isin't this the only way now:

     

    @Model.MacroParameters["yourParameter"]

  • stefan 4 posts 24 karma points
    Jun 03, 2013 @ 15:17
    stefan
    0

    thank you for posting the solution!

  • Jay 49 posts 211 karma points
    Dec 29, 2014 @ 12:53
    Jay
    0

    I'm currently trying to pass parameters to my Razor view, but my Model.MacroParameters remains empty.

    I've got this in my template (taken from this example):

    @Umbraco.RenderMacro("myMacroAlias", new { name = "Ned", age = 28 })
    

    So how come my Model.MacroParameters isn't showing any key/value pairs?

  • Jay 49 posts 211 karma points
    Dec 29, 2014 @ 13:14
    Jay
    0

    Problem solved.

    It was because I hadn't set up the macro parameter on the parameters tab in the macro section.

Please Sign in or register to post replies

Write your reply to:

Draft