Copied to clipboard

Flag this post as spam?

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


  • Simon 692 posts 1068 karma points
    Jun 02, 2015 @ 17:05
    Simon
    0

    Passing ViewBag through RenderMacro

    Hi Guys,

    Do you have an idea how can I pass the page ViewBag to the Macro Partial View through the RenderMacro extension method?

    something like the below:

    @Umbraco.RenderMacro("GetWorkItemUsedServices", new  { "Passing the View Bag" , ViewBag })

    I need to pass the ViewBag since I can eventually need to assign a value to the viebag and use the same viewbag to read the value set in the master page layout,

    Appreaciate any help.

    Thank you.

  • Alex Skrypnyk 6148 posts 24077 karma points MVP 8x admin c-trib
    Jun 02, 2015 @ 18:35
    Alex Skrypnyk
    0

    Simon, you don't need pass ViewBag to the macro, it has to be accessible from all razor files.

  • Simon 692 posts 1068 karma points
    Jun 02, 2015 @ 18:40
    Simon
    0

    Hi Alex,

    But I have a problem that if I set a viewbag value in my partial view, I cannot get that value from my master page. That's why I am trying this way.

    Do you have an idea how can I set a value in the viewbag in my partial view and access it in my master page?

    Thank you.

  • Alex Skrypnyk 6148 posts 24077 karma points MVP 8x admin c-trib
    Jun 02, 2015 @ 18:45
    Alex Skrypnyk
    0

    Can you inherit view from UmbracoViewPage ?

    Thanks

  • Simon 692 posts 1068 karma points
    Jun 02, 2015 @ 18:49
    Simon
    0

    Hi Alex,

    You mean changing the partial view inheriting from @inherits Umbraco.Web.Macros.PartialViewMacroPage to Umbraco ViewPage?

    thank you.

  • Simon 692 posts 1068 karma points
    Jun 02, 2015 @ 18:52
    Simon
    0

    I tried it but not success:/

  • Alex Skrypnyk 6148 posts 24077 karma points MVP 8x admin c-trib
    Jun 02, 2015 @ 19:09
    Alex Skrypnyk
    0

    If you want to access the ViewData that you've set on the master ViewContext's on a ChildAction being rendered from the master's ViewContext then you need to use @ViewContext.ParentActionViewContext.ViewData["ErrorMessage"]

    The ParentActionViewContext in this example is the ViewContext that is rendering the Umbraco template, not the ChildAction. That is because when you POST (whether inside of Umbraco or normal MVC), you are posting to a new Action and the rendering process starts from scratch, when you validate your model, update the ViewData, etc... this all happens on what will become the 'master' ViewContext when the view renders. This view then will render your ChildAction.

    http://stackoverflow.com/questions/27990225/how-to-use-viewdata-and-viewbag-with-umbraco-surface-controllers

  • Simon 692 posts 1068 karma points
    Jun 02, 2015 @ 21:11
    Simon
    0

    Hi Alex,

    I want the other way: since I need to set value in the PartialView and access it in the master page layout.

    Any idea?

    Kind Regards

  • Alex Skrypnyk 6148 posts 24077 karma points MVP 8x admin c-trib
    Jun 03, 2015 @ 11:28
    Alex Skrypnyk
    0

    Hi Simon,

    It's wrong way to work with partials. You have to inherit from top to the partial.

    Kind Regards

  • Simon 692 posts 1068 karma points
    Jun 03, 2015 @ 11:33
    Simon
    0

    Hi Alex,

    What I want is just to communicate between the macro partial view and the master layout.

    I need to change the meta description value and the value is generated in the macro partial view.

    That's the hassle for.

    Any idea pls or have you encountered a solutions for this?

    Thank you.

Please Sign in or register to post replies

Write your reply to:

Draft