asp.net-mvc - MVC Controller 与开箱即用的 Sitecore Controller

标签 asp.net-mvc sitecore sitecore6

我一直在阅读这里提供的许多关于 MVC 的博客:
http://www.sitecore.net/Community/Technical-Blogs/John-West-Sitecore-Blog.aspx

但是,我无法解释/说服自己/团队:

  • 何时使用自定义控件与开箱即用的站点核心 Controller ?
  • 什么时候调用 Out of Box Controller?
  • 自定义控件与开箱即用 Controller 的优势?
  • 如果我们开箱即用,我们是否应该在 View 中包含所有业务逻辑。这是可测试的吗?

  • 我也看了下面,仍然不确定:
    https://bitbucket.org/demoniusrex/launch-sitecore-mvc-demo

    任何帮助将不胜感激。

    最佳答案

    虽然我大致同意 Kevin Obee 的说法,但我认为值得提醒自己的是, Controller 在 Sitecore 中被用作两个不同的角色:

  • 页面级 Controller (由项目路由调用)
  • 组件级 Controller (由重新命名机制调用)

  • 何时使用:自定义 Controller /默认 Sitecore Controller

    页面级 Controller

    任何匹配项目路径的路由都将默认使用 IndexSitecore.Mvc.Controllers.SitecoreController 的操作.此操作将根据项目的布局配置返回一个 ViewResult。

    如果您需要更改此行为(例如影响整个页面的某些内容),您可以在项目(或项目的标准值)上指定自定义 Controller 和操作。对于自定义 Controller ,您可以推出自己的或子类化默认 Controller 。

    组件级 Controller

    对于 ViewRendering Sitecore 在不需要特定 Controller 的情况下呈现 Razor View (好吧,我猜是页面级 Controller 在起作用 - 但想象一下,Sitecore 提供了一个默认 Controller ,它使用 mvc.getModel 管道获取模型并将其提供给 Razor View )。

    对于 ControllerRendering您提供了一个可以执行逻辑的自定义 Controller (请参阅 Kevin 的回答)并为 View 提供模型。子类化没有任何好处 Sitecore.Mvc.Controllers.SitecoreController .

    何时调用 Controller

    页面级 Controller

    页面级 Controller 上的操作由路由引擎调用。

    组件级 Controller

    当页面 View 呈现时调用 ControllerRendering 上的操作。

    使用的好处:自定义 Controller /默认 Sitecore Controller

    与默认 Sitecore Controller 相比,自定义 Controller 的优势在于您可以控制逻辑。使用默认 Sitecore Controller 的好处是 Sitecore 为您提供逻辑。

    我们是否应该在 View 中包含所有业务逻辑

    不。(见凯文的回答)

    关于asp.net-mvc - MVC Controller 与开箱即用的 Sitecore Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14957451/

    相关文章:

    continuous-integration - 如何保持 Sitecore 数据库一致?

    Sitecore Axes.IsDescendantOf/Axes.IsAncestorOf - 包括在内?

    asp.net-mvc - asp.net mvc 如何为 html.dropdownlist 添加占位符

    javascript - 如何在 MVC 5 Razor 中调用和刷新局部 View ?

    customization - 限制未经身份验证的外部网用户对 Sitecore Media Assets 的访问

    sitecore - 使用 Sitecore 发布代理并在特定时间发布项目

    asp.net-mvc - ASP.NET MVC LINQ 查询

    asp.net-mvc - MVC : Use Display name as column header with CSVHelper

    sitecore - 将工作流添加到 sitecore 6.5 中的现有项目

    sitecore - 从序列化项目创建包