SitecoreMvcAreas:允许 Sitecore MVC 渲染和布局指定 MVC 区域的实现

  • K7_772461
  • 65.1KB
  • zip
  • 0
  • VIP专享
  • 0
  • 2022-05-20 22:25
#SitecoreMvcAreas 允许 Sitecore MVC 渲染和布局指定 MVC 区域的实现。 使用 MVC 渲染时,Sitecore 不提供指定渲染应存在于其中的 MVC 区域的特定方法。 这将为开发人员提供一种在定义呈现定义项时在内容树中指定 MVC 区域名称的方法。 ##为什么? MVC 区域用于告诉 MVC 正在运行的网站中资产的位置。 在 SCORE 中,我们建议使用 MVC 区域来隔离多租户环境的每个租户内的资产。 控制器渲染视图分辨率在创建控制器渲染时,MVC 将“期望”视图位于特定位置(基于控制器如何引用视图)。 DisplayTemplates 和 EditTemplates 显示和编辑模板可用于将 UI 代码模块化为旨在呈现特定模型类的小型 cshtml 文件。 这可以用来代替使用用作 HTML 格式化程序的帮助程序(或更糟的代码片段)格式化您的输
#SitecoreMvcAreas An implementation to allow Sitecore MVC renderings and layouts to designate an MVC Area. When using MVC renderings, Sitecore does not provide a specific way to designate the MVC area that the rendering should exist within. This will provide the developer a way to specify the MVC area name within the content tree when defining the rendering definition items. ##Why? The MVC Area is used to tell MVC the location of assets within the running website. In SCORE, we recommend the use of MVC areas to isolate assets within each tenant of a multi-tenant environment. Controller rendering view resolution When creating controller renderings, MVC will "expect" that the view is located in a specific place (based on how the view is referenced by the controller). DisplayTemplates and EditTemplates Display and Edit Templates can be used to modularize the UI code to small cshtml files that are designed to render specific model classes. This can be used instead of formatting your output with helpers (or worse with code snippets) that are used as HTML formatters. ##How? There is no single obvious way to tell a Sitecore rendering or layout document about it's area name. Also, we should avoid the obvious - modifying any built-in templates that Sitecore offers. Since there is no obvious single way to do this, it might be a combination of techniques - so we will introduce a new pipeline into Sitecore to get the area name for a specific rendering being processed by the RenderRendering pipeline. ###2 Approaches We have included 2 approaches in the pipeline - first, using a new rendering folder template that can specify the area name for inclusive renderings nested within the folder. Second, and since you cannot use the same approach with layout folders, another method is provided to look at the view path and "extract" the area name from the path of the cshtml or ascx file. ##Usage 1. Add the folder "master" to your serialization folder in the Sitecore data directory, then on the developer tab, use the update tree button to add the needed templates into your instance of Sitecore. 2. Next, build and copy the DLLs from the solution into your instance, and add in the patched configuration file to the App_Config/Include folder. 3. To use the rendering folder data template, simply replace a normal rendering folder for your renderings (for example, /sitecore/Layout/renderings/MyRenderings) with the provided "Rendering Folder with Area" template, and specify an area name on the item content tab. You can test it by creating a controller rendering and using the syntax ''' return PartialView(model); ''' - MVC should automatically find the proper view file in the folder /Areas/AreaName/Views/ControllerName/ActionName.cshtml For the view renderings and layout documents, the other processor will automatically find the area name based on the folder pattern: /Areas/<Area Name>/views/....