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 @ 22:39
    Simon
    0

    Modifying ViewBag Value in Macro Partial View in Umbraco

    Hi Guys,

    I have a siutation where I need to store a value in a view bag from a macro partial view, in order to be able to access it in the master page layout.

    Considering that Views and Partials get their own ViewBag, as discussed here (http://www.codedisqus.com/0yNeUVXqgq/modifying-mvc-3-viewbag-in-a-partial-view-does-not-persist-to-the-layoutcshtml.html), therefore, can I achieve it Umbraco, to declare a ViewBag in macro partial view and access it in the master page layout from where the parent view in inherting from?

    Much appreicated.

    Thank you.

    Kind Regards

  • Urvish 252 posts 776 karma points
    Jun 03, 2015 @ 06:24
    Urvish
    0

    Hi Simon,

    Yes you can achieve it from Umbraco. Umbraco runs under the MVC render engine. So you can use what ever the features available in MVC.

    See below post.

    http://forums.asp.net/t/1705637.aspx?Transfer+values+between+View+and+PartialView+using+ViewBag+

    Hope it will help you to get or set Viewbag values from views.

    Regards,

    Urvish Mandaliya

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

    Hi,

    It doesn't work using the @ViewContext.Controller.ViewBag.DayBlockClass = "dayName".

    When I set the value of the view bag in the partial view it does not store the value in order to retrieve the value then back to the layout view.

    Others suggest to pass the viewbag from the view to the macro partial view but I don't know how to achive this, as described here (http://www.codedisqus.com/0yNeUVXqgq/modifying-mvc-3-viewbag-in-a-partial-view-does-not-persist-to-the-layoutcshtml.html)

    Any ideas please?

    Thank you.

    Kind Regards

Please Sign in or register to post replies

Write your reply to:

Draft