Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more

Optimizely Logo
  • Products
    • Content Marketing Platform
      • Overview
      • Features
    • Content Management System
      • Overview
      • SaaS CMS
    • Commerce Connect
    • Configured Commerce
    • Web Experimentation
      • Overview
      • Features
    • Feature Experimentation
      • Overview
      • Features
    • Data Platform
    • Product skillset
    • Product roadmap
    • Product migration
  • Documentation
    • Developer guides
    • User guide
    • APIs and libraries
      • Content Management System
      • Commerce Connect
      • Campaign
      • Search & Navigation
      • Community API
      • REST APIs
    • Releases
    • Upgrading
      • Content Management System
      • Commerce Connect
      • Search & Navigation
      • Forms
      • Personalization
      • Service API
  • OMVPs
    • Become a member
    • Benefits
    • OMVP events
    • OMVP members
    • Application and nomination
    • Digital badges
  • Community
    • Events
    • Developer updates
    • Happy hours
    • Forums
    • Blogs
    • Slack
    • Product feedback
    • Community recognition program
  • Resources
    • Optimizely Nuget feed
    • .NET
      • About .NET
      • Why upgrade?
    • Education
      • Live Training
      • Work Smarter
      • Masterclasses
      • Certification
      • SME program
    • Videos
    • Services Description
    • Support
  • Register
  • Log in
  • Log in - Opti ID
All Content Documentation Forums User Guide Support Help Center Blogs Releases Bug List Class libraries
People
AI OnAI Off
Home /
Taylor_Oshyn
Taylor_Oshyn
Mar 1, 2016
  2663
(0 votes)

Developing with Episerver MVC

Starting with version 7, Episerver fully supports the .NET MVC Framework and Razor syntax for presentation elements. Unlike other CMS products in the market, Episerver follows the MVC Framework patterns and standards as closely as possible. In this article I’m going to describe how the MVC Framework fits with Episerver’s data model and presentation elements.

Episerver integrates tightly with Visual Studio, so everything you need to start developing Episerver sites is readily available at the Visual Studio Gallery. Just search for the Episerver CMS Visual Studio Extension, download it, and install it. When creating a new project, select the Episerver Web Site [MVC], and it will include all the required scaffolding for your project. It will automatically download the latest Episerver DLLs for you via NuGet. You can build and run your project directly using VS’s built-in IIS Express, or by deploying to a regular IIS web site. When deploying to a regular IIS web site, make sure you attach the included MDF database (under App_Data) to any SQL server instance (Express included), and changing the connection string in web.config.

The fundamental building blocks in Episerver are Page Types. These define the content fields (Properties in Epi parlance) of the pages that will be created on the website. Additionally, by using a Template, they also define how the content is going to be displayed in the page. In MVC, we are going to separate these concepts in three parts: the Page Model, the Page Controller, and the Page View. The Page Model is the actual definition of the Page Type. It contains the fields and their content types. You create Page Model classes by using the VS template for “Page Type” included in the Episerver VS Extension. After creating a Page Model class, you can manually add more properties (fields) as needed.

The Page Controller is the intermediary between the Page Model (Type) and the View. Episerver Controllers inherit from the generic PageController class. You can use the Episerver VS Extension’s “Page Controller [MVC]” template to create these controller classes. The Page Model class is used as the parameter of the generic PageController class. With this, Epi knows what Page Model has to use to render the content. You must implement the default Index method that returns a standard ActionResult object. As you can see in the code sample, Episerver will pass an object of the Page Model type you defined as the parameter of the PageController generic class. The return clause uses the standard MVC View method, using the Page Model object as a parameter.

Finally, for the presentation of the data, we use the Page View. Following .NET MVC Framework’s conventions, the Page View must be stored under the Views folder, in a folder with the name of the controller (without the “Controller” part), and must be named Index.cshtml (since the action is called Index). You can use the Episerver VS Extension’s “Page Partial View [MVC Razor]” to create these views.

After building and deploying your code to your Episerver instance, now you can create pages based on the Page Type you just created. There is no need to create custom MVC routes, Episerver will handle everything in a content-oriented way.

Another important feature in Episerver is the capability to create modules that can be placed and reused anywhere in your site. These are called Blocks. They use a similar data model as for Pages. Instead of a Page Type, you create a Block Type. Episerver VS Extension includes a “Block Type” class template.

Some Blocks may need additional data that can’t be included in the Block Type definition (e.g. child pages in a reusable navigation menu). For this, you can create a custom model with a reference to the Block Type. You will use this Model later in your Controller to populate the additional data, and View to display it.

Similar to a Page Controller, you create a Block Controller to handle the interactions between the Type, Model and View. You can use the Episerver VS Extension’s “Block Controller [MVC]” template to create these classes. Same as Page Controllers, Block Controllers take as a parameter to the generic class the Block Type class. The Action method (Index) takes an object of Block Type class. But in your Action, you might want to create additional logic to populate the Custom Model, and pass that Model object to the View.

Finally, to render Blocks you must create a Block View. Using the same conventions as for Pages, create a new View using the Episerver VS Extension’s “Block Partial View [MVC Razor]” template. Make sure you declare the right model in the View, especially when dealing with custom models.

Make sure you put sections in your other Page Views to contain the blocks by using the @section directive.

Now you can use the Block anywhere in your site where you have block sections by dragging it from the assets pane.

In a next blog post, I’ll cover how to post a form in Episerver MVC. To get updated about this and other posts, follow us on Twitter @Oshyn_Inc, or register for our email list at http://oshyn.com/resources/blog.html and check out our website as well!

 

Mar 01, 2016

Comments

Please login to comment.
Latest blogs
Optimizely Configured Commerce and Spire CMS - Figuring out Handlers

I recently entered the world of Optimizely Configured Commerce and Spire CMS. Intriguing, interesting and challenging at the same time, especially...

Ritu Madan | Mar 12, 2025

Another console app for calling the Optimizely CMS REST API

Introducing a Spectre.Console.Cli app for exploring an Optimizely SaaS CMS instance and to source code control definitions.

Johan Kronberg | Mar 11, 2025 |

Extending UrlResolver to Generate Lowercase Links in Optimizely CMS 12

When working with Optimizely CMS 12, URL consistency is crucial for SEO and usability. By default, Optimizely does not enforce lowercase URLs, whic...

Santiago Morla | Mar 7, 2025 |

Optimizing Experiences with Optimizely: Custom Audience Criteria for Mobile Visitors

In today’s mobile-first world, delivering personalized experiences to visitors using mobile devices is crucial for maximizing engagement and...

Nenad Nicevski | Mar 5, 2025 |

Unable to view Optimizely Forms submissions when some values are too long

I discovered a form where the form submissions could not be viewed in the Optimizely UI, only downloaded. Learn how to fix the issue.

Tomas Hensrud Gulla | Mar 4, 2025 |

CMS 12 DXP Migrations - Time Zones

When it comes to migrating a project from CMS 11 and .NET Framework on the DXP to CMS 12 and .NET Core one thing you need to be aware of is the...

Scott Reed | Mar 4, 2025

See all blogs
Optimizely Logo

About Optimizely

  • Optimizely.com
  • Optimizely certification
  • Job openings
  • License center

Community

  • OMVP program
  • Happy hours
  • Forums
  • Blogs
  • Slack
  • Product feedback

Learning resources

  • Partner portal
  • Developer guides
  • User guide
  • Video tutorials
  • GitHub
  • Optimizely Academy

Contact

Optimizely support

See the support page for contact information.

Feedback on Optimizely World

If you’d like to give feedback about this site, please click here. Thank you very much!
  • © Optimizely 2025
  • About Optimizely World
  • Privacy notice
  • Terms of use
  • Trust center
  • Compliance