0

我遵循了这个很好的教程,它解释了如何利用 Umbraco 作为内容交付系统来发挥更大的优势。Tutorial MVC Umbraco => 你的模型和视图不应该依赖于特定的 Umbraco 实现,这对于真正的前端开发人员来说是一个巨大的优势。

控制器继承自 Umbraco.Web.Mvc.RenderMvcController 以便从 CMS 访问数据。现在我的问题是我们不能使用@HTML.actionlink 进行导航,似乎只有SurfaceController 支持。

现在我的问题是我们如何在 Umbraco.Web.Mvc.RenderMvcController 中实现导航?我们还能使用原生的@HTML.actionlink 标签吗?

4

1 回答 1

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.

于 2013-08-19T12:30:26.607 回答