Copied to clipboard

Flag this post as spam?

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


  • Andrew Johns 6 posts 26 karma points
    Nov 23, 2016 @ 14:57
    Andrew Johns
    0

    Sharing custom model data between child actions

    I have non-umbraco data that I'd like to display on a page. I set up a Surface controller with multiple child actions relating to different partial views, but the result is that I'm making a separate calls to the database for each child action partly to get part of the same data.

    It seems like it'd be better to have my Controller request the data once in the constuctor or initial load, and share that data with each action.

    I'm not sure how that'd work in the world of Umbraco though - I have a feeling I need to use RenderMvcController instead of SurfaceController in order to hijack the initial load? How would I maintain the data between child actions?

  • David Peck 690 posts 1896 karma points c-trib
    Nov 23, 2016 @ 15:03
    David Peck
    0

    It's not an Umbraco issue, it's an MVC one.

    If you can't put it in to the route data when calling the action then you could either stick it in TempData (I think - I'm not sure on this you might need to call Html.RenderAction rather than Html.Action), or use the request cache.

    The request cache is probably the simpliest solution.

  • Andrew Johns 6 posts 26 karma points
    Nov 23, 2016 @ 16:12
    Andrew Johns
    0

    I think what I'm realising is that SurfaceController isn't the right approach for what I want, and that I'm better off using a RenderMvcController and custom model inheriting from RenderModel. That way I can populate the model when the page loads, and then pass that to the partial views.

    At least that's how I understand it would work, whether I can make it do that in practice is another question! Off to read more.

Please Sign in or register to post replies

Write your reply to:

Draft