Documentation Center

Setting up an Area (.NET)

SDL Digital Experience Accelerator uses the concept of Areas to separate different bits of code and functionality: there is a separate area for Core functionality and an area for each Module (add-ons to the Core). You can find these areas in the Areas folder in the root of your Web application. When you add custom functionality, create your own Areas to separate the functionality from Core and Module functionality.

About this task

An example of a module is GoogleAnalytics. Shared items are located in the Views Folder, for example the main layout used by all page views: Views/Shared/_Layout.cshtml.

Views are located in the Views folder, which has separate subfolders for each controller, and a Shared folder for shared views.

Procedure

  1. Open Visual Studio.
  2. Right-click the Web application and select Add > Area.
  3. Use Area names that do not clash with those of the Core or other Modules. It is recommended to use the following naming convention: CompanyNameAreaName. For example, create an area called MyCompanyOffers.
  4. In the Views subfolder, open Web.config for editing.
  5. In the system.web.webPages.razor, section, in the pages section, add namespace references in the namespaces section:
    <namespaces>
      <add namespace="System.Web.Mvc" />
      <add namespace="System.Web.Mvc.Ajax" />
      <add namespace="System.Web.Mvc.Html" />
      <add namespace="System.Web.Routing" />
      <add namespace="Sdl.Web.Mvc.Configuration"/>
      <add namespace="Sdl.Web.Mvc.Html"/>
      <add namespace="Sdl.Web.Common.Configuration"/>
      <add namespace="Sdl.Web.Common.Models"/>
      <add namespace="Sdl.Web.Common.Extensions"/>
      <add namespace="Sdl.Web.Site"/>
    </namespaces>
  6. Edit the SpecialOfferAreaRegistration.cs file which is created in the Area folder, to add a default route to ensure that any region or entity controller actions are activated within this area:
    using Sdl.Web.Mvc.Configuration;
    using Example.Models;
    
    namespace Example
    {
      /// <summary>
      /// AreaRegistration for SpecialOffer
      /// </summary>
      public class SpecialOfferAreaRegistration : BaseAreaRegistration
      {
        public override string AreaName
        {
          get 
          {
            return "MyCompanyOffers";
          }
        }
    
        /// <summary>
        /// Registration of Strongly typed models for SpecialOffer
        /// </summary>
        protected override void RegisterAllViewModels()
        {
          // Entity Views
          RegisterViewModel("SpecialOfferView", typeof(SpecialOfferModel));
        }
      }
    }

Results

You can now add specify custom Views and Models inside our SpecialOffer area.