HomeDev GuideAPI Reference
Dev GuideAPI ReferenceUser GuideGitHubNuGetDev CommunityDoc feedbackLog In
GitHubNuGetDev CommunityDoc feedback

In Optimizely Content Management System (CMS), a template can correspond to a MVC controller and a view, where the controller selects the view to display. The view contains the actual HTML template with embedded code, generating content sent to the client. Another alternative is to use Razor pages as templates.

Views are _.cshtml_ files stored by default in the_Views_ folder. Action-specific views, partial views, and layouts are used to reduce repetition. By convention in MVC, the default layout is named _\_Layout.cshtml_located in the \_Views/Shared_ folder. See [Views (Microsoft)](🔗).

To avoid repetition, you can create a [base controller](🔗) to be used by the page base class and inherited by other controllers. You can also create _view models_ and _partial views_ to make your views more flexible, for example, when creating menus and other navigation components.

## View models

There are several ways of passing data to views. A view model is useful if you want to pass data beyond `IContentData` objects into your views. You can define a model type in the view, and pass an instance of this type to the view from the action.

In the following example, you use an interface `IPageViewModel` and a `DefaultPageViewModel` based on a `SitePageData` base class.

**Example:** Controller for a Standard page based on a `PageController`, using a `DefaultPageViewModel`.

**Example:** The `DefaultPageViewModel` with the `IPageViewModel` interface, and a `ContentExtensions` class used for rendering a left navigation section.

`PropertyFor` is one of many Optimizely `Html` helpers. `PropertyFor` is frequently used for displaying markup for properties, and automatically enables on-page editing of the property when used.

**Example:** View for the Standard page, displaying the left navigation, with page name and main body properties.

## Partial views

A partial view is a view that is rendered within another view. The HTML output generated is rendered into the calling view. Common layout elements are usually defined in one view, and specific non-reusable layout elements are defined using partial views. See [Partial views (Microsoft)](🔗) for more information.

**Example:** A partial view for rendering a simple top navigation listing subpages to the start page, with links to each page.

**Example: **The _Navigation_ partial view added to the shared \_Layout view, resulting in a top menu display for all pages.

## Related topics

  • [Views (Microsoft)](🔗)

  • [Partial views (Microsoft)](🔗)

  • See the [ASP.NET Core framework documentation](🔗) for more details on how to work with views and view models.