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,
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.
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.
Simon, you don't need pass ViewBag to the macro, it has to be accessible from all razor files.
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.
Can you inherit view from UmbracoViewPage ?
Thanks
Hi Alex,
You mean changing the partial view inheriting from @inherits Umbraco.Web.Macros.PartialViewMacroPage to Umbraco ViewPage?
thank you.
I tried it but not success:/
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
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
Hi Simon,
It's wrong way to work with partials. You have to inherit from top to the partial.
Kind Regards
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.
is working on a reply...