0

I have followed this nice tutorial which explains how you can take even more advantage of using Umbraco as a content delivery system. Tutorial MVC Umbraco => Your model and views should not depend on specific Umbraco implementations which is a huge advantage for real front-end developers.

The controller inherited from Umbraco.Web.Mvc.RenderMvcController in order to access the data from the CMS. Now my problem is that we can't use @HTML.actionlink for navigation, it seems that this is only supported in SurfaceController.

Now my question is how would we implement navigation inside Umbraco.Web.Mvc.RenderMvcController? Can we still use the native @HTML.actionlink tag?

tereško
  • 58,060
  • 25
  • 98
  • 150
JVGAG
  • 107
  • 2
  • 12

1 Answers1

1

No you can't. Simply because all requests pass through a single action. In order to retrieve a path to a CMS-managed page, you need to use the node/content traversal the @Model provides. See here for more details on this.

Edit

To clarify, the author of the article is suggesting that the Umbraco implementation should be more in line with a traditional MVC implementation with little or no logic in the views. Therefore, any querying of node data should happen prior to the view (e.g. in the Mappers). So this is where you would have to retrieve the links.

Umbraco's default MVC implementation forces all requests to go via a single action on a single controller. The author's implementation allows the requests to be shared across one controller per document type - which is better IMO. But it still means that things like Html.ActionLink are redundant in the views since there isn't an action per page.

Further edit

If you wanted to build a navigation list with a combination of Umbraco-managed pages and non-Umbraco pages, regardless of the implementation, I would:

  1. Create a child action and view for the navigation in a separate NavigationController that inherits from the SurfaceController
  2. Use the this.CurrentPage property of the inherited SurfaceController to traverse the Umbraco content cache to retrieve the relevant Umbraco-managed pages. You can then use the Url property of each page result to get its path, and the Name property to get the page title
  3. Use this.Url.Action("action", "controller") to retrieve the paths to specific non-Umbraco actions. Alternatively, if the pages are database-managed, use you data layer (e.g. EF, NHibernate, PetaPoco) at this point
  4. Combine these in a Dictionary to make the list you require where the Key is the path and the Value is the page title
  5. Pass this down to the view as the view model.

Of course there any many more things to consider like caching, but in a nutshell, that's a fairly basic implementation.

Digbyswift
  • 10,310
  • 4
  • 38
  • 66
  • Then i actually don't understand the value of the tutorial in my original post. You are forced to use the Umbraco tool itself to build up a website. I don't see any additional value of using a external IDE like visual studio. Also the real MVC pattern is hidden for the developer, under the hood umbraco is using MVC, but you can't say that you are developing like MVC pattern describes. – JVGAG Aug 20 '13 at 14:53
  • Well many sites aren't purely about the content but data. Imagine a shopping site or a investment funds site. These sites need content but almost all their data comes from catalogues or data sources. So it is often the case that you will use Umbraco as the basis for your site and have additional non-Umbraco controllers, views etc outputting non-CMS-managed data. I understand where the article is coming from, but for smaller content-driven sites, the approach could be overkill. – Digbyswift Aug 20 '13 at 15:00
  • But How should i implement navigation between umbraco (rendermvccontroller) and non umbraco controller ? – JVGAG Aug 20 '13 at 18:54
  • I've updated my answer but you really are asking a separate question here. – Digbyswift Aug 21 '13 at 07:32