Copied to clipboard

Flag this post as spam?

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


  • Jigar Gala 14 posts 74 karma points
    Oct 10, 2015 @ 16:30
    Jigar Gala
    0

    Rendering a Partial View via Razor Macro

    Hi

    I am writing a Razor Macro wherein I get the name of a Partial View dynamically. I need to pass a list of Nodes to this Partial View and render it dynamically within the Razor Macro.

    Is it possible? Any directions on how can it be done?

    Thanks

  • Marc Goodson 2155 posts 14408 karma points MVP 9x c-trib
    Oct 10, 2015 @ 23:44
    Marc Goodson
    100

    Hi Jigar

    Is your Razor Macro a Partial View Macro ? or Dynamic Node Razor Macro.

    If you have a Partial View Macro then you should be able to call a further Partial view and pass a custom model of your list of nodes, eg

      @{
            IEnumerable<IPublishedContent> myNodeList = Umbraco.TypedContent(new string[] {"1123","1127","1125"});
    // (or however you get your list of nodes)
    
    //Render partial calls the partial view, and allows you to pass the custom model.
            Html.RenderPartial("~/Views/Partials/TestPartialView.cshtml", myNodeList);
        }
    

    then your partial view should have a model based on the list of nodes eg.

    @inherits UmbracoViewPage<IEnumerable<IPublishedContent>>
    

    then you should be able to loop through the nodes in your partial view with

    <ul>
    foreach (var item in Model){
    <li>@item.Name</li>
    }
    </ul>
    
  • Jigar Gala 14 posts 74 karma points
    Nov 02, 2015 @ 11:05
    Jigar Gala
    0

    Thanks Marc
    That worked like a Charm!!

Please Sign in or register to post replies

Write your reply to:

Draft