Umbraco MVC Implementation - View does not depend on Umbraco implementations

痞子三分冷 提交于 2020-01-24 01:25:11

问题


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?


回答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.



来源:https://stackoverflow.com/questions/18310483/umbraco-mvc-implementation-view-does-not-depend-on-umbraco-implementations

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!