Optimizely Logo
  • Products expand_more expand_more
    • Content Marketing Platform chevron_right
      • Overview
      • Features
    • Content Management System chevron_right
      • Overview
      • SaaS CMS
    • Commerce Connect
    • Configured Commerce
    • Web Experimentation chevron_right
      • Overview
      • Features
    • Feature Experimentation chevron_right
      • Overview
      • Features
    • Data Platform
    • Product skillset
    • Product roadmap
    • Product migration
  • Documentation expand_more expand_more
    • Developer guides
    • User guide
    • APIs and libraries chevron_right
      • Content Management System
      • Commerce Connect
      • Campaign
      • Search & Navigation
      • Community API
      • REST APIs
    • Releases
    • Upgrading chevron_right
      • Content Management System
      • Commerce Connect
      • Search & Navigation
      • Forms
      • Personalization
      • Service API
  • OMVPs expand_more expand_more
    • Become a member
    • Benefits
    • OMVP events
    • OMVP members
    • Application and nomination
    • Digital badges
  • Community expand_more expand_more
    • Events
    • Developer updates
    • Happy hours
    • Forums
    • Blogs
    • Slack
    • Product feedback
    • Community recognition program
  • Resources expand_more expand_more
    • Optimizely Nuget feed
    • .NET chevron_right
      • About .NET
      • Why upgrade?
    • Education chevron_right
      • Live Training
      • Work Smarter
      • Masterclasses
      • Certification
    • Videos
    • Support
  • Login
filter_listAll Content articleDocumentation forumForums menu_bookUser Guide support_agentSupport Help Center rss_feedBlogs new_releasesReleases bug_reportBug List codeClass libraries
groupPeople
search
AI OnAI Offsmart_toy
Home / Blogs / 2016 / 3 /
Taylor_Oshyn
Taylor_Oshyn
Mar 1, 2016
visibility 7805
star star star star star
(9 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

Henrik Fransas
Henrik Fransas Mar 1, 2016 08:40 PM

A good explaining on MVC, I just want to give a couple tips regarding the code

First, when you are getting pages with getchildren always filter the result with FilterForVisitors because otherwise you could end up showing links in the menu that are not accessible.

Then a little optimization is to always use IContentLoader when you are only fetching things.

Looking forward to reading the next post

Jacob Khan
Jacob Khan Mar 2, 2016 11:01 PM

Nice to see you blogging. Also looking forward to the next post. Keep them coming!!

error Please login to comment.
Latest blogs
Architecting an Enterprise-Grade Development Pipeline in Optimizely SaaS CMS

Most enterprise teams show up to Optimizely SaaS CMS with a clear roadmap for their release pipeline: DEV → QA → Stage → Prod. Four logical...

Vipin Banka | Jul 12, 2026

Bynder DAM Connector for Optimizely SaaS CMS: Improved Metadata Property Synchronization

While working with the Bynder DAM Connector for Optimizely SaaS CMS , one of the key areas I explored was how Bynder asset metadata is synchronized...

Vipin Banka | Jul 11, 2026

Optimizely DXP: Every Supported Culture, One Searchable Page

Quick one for anyone building multi-language sites on Optimizely DXP. I put together a reference tool listing all 806 supported cultures. More...

Adnan Zameer | Jul 10, 2026 |

A day in the life of an Optimizely OMVP: London Meetup 2026

On 2nd July 2026 the Optimizely London Developer Meetup returned to The Lightwell, and the running theme across the evening was less about individu...

Graham Carr | Jul 10, 2026

Optimizely’s Summer ’26 Roadmap: The CMS Is Starting to Look Less Like a Publishing Tool and More Like Marketing Infrastructure

Optimizely’s Summer ’26 Product Roadmap event was not just a list of product updates. At least, that is not the part I found most interesting. The...

Augusto Davalos | Jul 9, 2026

Optimizely Content JS SDK v2.1.0 — What's New and Why It Matters

  v2.1.0 of the Optimizely Content JS SDK and CLI landed on July 7, 2026. This is a substantial release bringing a wave of capabilities for...

Vipin Banka | Jul 8, 2026

See all blogs
arrow_upward
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 2026
  • About Optimizely World
  • Privacy notice
  • Terms of use
  • Trust center
  • Compliance
  • 3rd Party Integrations