0
votes

Is there any way of either overriding the default RenderMvcController to output a custom RenderModel for every route. It's possibly by hijacking routes but I want to put some custom data which will be used on every page.

For example, on an e-commerce site every page displays the basket information. Ideally this would be available in the RenderModel for every view. Is there a way of changing the default Controller to a custom one which will output an extended render model with a Basket attribute?

Update:

This is now supported in Umbraco 6.1.0+ the documentation is at the end of this page: http://our.umbraco.org/documentation/Reference/Mvc/custom-controllers

1
I assume this is Umbraco v4.10?Digbyswift
Hi, Yes it is v4.10, I've updated the question to make that clearSteve Temple

1 Answers

3
votes

The solution I would consider is instead of trying to crowbar custom data into Umbraco's default page model, consider having a BasketSurfaceController and rendering the basket contents to the screen using @Html.Action("HeaderDisplay", "BasketSurface") or something similar. This way you could keep the view model independent and have it displayed as part of the _Layout.cshtml or on the specific pages you need.

Also using this approach, you can maintain a collection of specific basket-related views all fed by the same Controller with a clean separation from Umbraco's model.

See the documentation on Child Actions for further info.

Update:

On re-reading the documentation, I can see that this is possible in 4.10+ and quite easily. The documentation is here but in a nutshell you can override requests to each document type or override all requests by replacing the default controller.

Although I would still advocate the ChildAction approach for this particular scenario, overriding the document type controller to pass down a custom view model is ideal for passing a pre-formed model that is specific to the page (e.g. a blog entry with comments. associated categories) and/or passing a model that contains data that isn't available from the page itself but is required on each page (e.g. the site name, domain, locale, global tracking/affiliate code, metadata).