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?
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.
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.
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?
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.
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.
is working on a reply...