You are on page 1of 2

Sitefinity CMS - MVC modes

There are three modes of MVC in Sitefinity CMS:


1. Classic
2. Pure
3. Hybrid
Classic MVC mode:
Classic mode should be familiar to all ASP.NET MVC developers, because it is jus
t plain controllers and views. The only difference is in the way you register yo
ur routes.
First, you should implement your custom controller, view and model that you want
to use in classic mode. To learn how it s done, read Creating custom models, contro
llers and views . After you have your controller, you should register a route fo
r it.
Registering a route
This step is a little different in Sitefinity, because of the specifics of its M
VC support. Instead of using the RouteTable directly, you have to use the Bootst
rapper class to register routes.
protected void Application_Start(object sender, EventArgs e)
{
Bootstrapper.MVC.MapRoute(
"Classic",
"customprefix/{controller}/{action}/{id}",
new { controller = "Feature", action = "Index", id = (string)null }
);
}
In the registration itself, the only difference with a regular ASP.NET MVC proje
ct is that we use Bootstrapper.MVC instead of RouteTable.
Pure MVC mode:
Pure mode lets you use MVC controllers as widgets on a Sitefinity page. You can
compose the whole page using MVC widgets only, and no WebForms functionality is
allowed in this mode. The major benefit is that you have complete control over t
he markup and how the content from the controllers is rendered. There are no for
ms or ViewState that you don t want to use.
In this mode you can add multiple controllers on the same Sitefinity page. This
may be confusing for developers who have used regular ASP.NET MVC projects, wher
e controllers correspond to a single page (url). We ve taken the page abstraction lo
wer. You can think of a Sitefinity page as playing the role of the MVC runtime,
which sits before your controllers are invoked and composes the markup each of t
hem generates.
Once created, this template and all pages based on it can host MVC based widgets
only. You cannot use the WebForms model in this mode. The toolbox will be filte
red to only show the custom controllers you have developed as widgets.
Hybrid MVC mode:
You can think of Hybrid mode as a way to use the best of both worlds
MVC and WebFo
rms. Hybrid mode lets you use MVC widgets and WebForms widgets on the same page.
You can implement your controllers the way you are used to, and at the same tim
e have WebForms controls that use postbacks. This might sound weird to some, but

we decided to give you as many options as we can.


Create a hybrid template and page
To use Hybrid mode, you must create a template and specify
) as the value of Web Framework in advanced settings.

WebForms and MVC (hybrid

Once created, this template and all pages based on it can use both the old WebFo
rms widgets, as well as custom MVC widgets.
In order for this to work, the Sitefinity engine creates a page object, but also
routes to all MVC controllers that you have on the page and inserts their marku
p into the output. This works in exactly the same way that ASP.NET MVC does, so
there are no hacks or workarounds
you can fully expect your controllers to behave
like they would normally.
Which mode should I use?
The mode used depends on your development process as well as the functionality y
ou want to implement.
If you want clear markup, a lot of client code and are willing to sacrifice the
ViewState and postback model, use Pure mode.
If you want to use the built-in Sitefinity widgets, together with custom MVC con
trollers on the same page, you have to use the hybrid mode.
If you are porting an existing MVC app into sitefinity, and want precise control
over your URLs, you may want to use the classic mode.
Those are not the only scenarios and there are always tradeoffs to be made. We a
re providing options for you to use the best of both worlds, but which one you c
hoose is up to you. We cannot confidently recommend the best practice without kn
owing your project functionality and objectives.

You might also like