Develop with Sitefinity CMS and ASP.NET MVC
Sitefinity CMS multi-layer architecture is designed and built around the key concepts of extensibility, interoperability, integration, and flexibility. Sitefinity CMS provides you with choices of how to implement your logic and meeting your requirements, for example, working with third-party software and utilizing various approaches on how to solve a problem. The recommended approach is to work with ASP.NET MVC framework to build websites and interfaces, widgets, interactions, and applications. With MVC development, you benefit from:
- Full control over the whole markup
- You can extend the routes, controllers, filters, and actions in MVC and also to define your own HTML Helpers
- MVC widgets are automatically registered in the toolbox
- Controllers in MVC are decoupled from any state and can be easily tested and mocked
- Loosely coupled components that make parallel development possible for different components
- Performance is optimized since MVC is not coupled with ViewState
- MVC architecture pattern complements the SOLID principles
You can also work with ASP.NET Web Forms technology, or use both of them, depending on your development needs and requirements. Developers with an MVC background can implement custom controllers and views that can be also used in a Sitefinity CMS project. With Sitefinity CMS, you can combine both MVC and WebForms widgets and use them on the same page. You can create new functionality using MVC, whilst not breaking anything that you are currently working with.
MVC controllers and Sitefinity CMS widgets
With Sitefinity CMS, you can leverage the classic, pure, and hybrid modes of MVC. The mode you use depends on your development process as well as the functionality you want to implement. The classic mode, as the name suggests, is the mode in which a page is represented by one controller (in essence, bypassing Sitefinity CMS page routes) – as it is outside of the context of Sitefinity CMS. The pure and hybrid modes are Sitefinity-specific and bring ASP.NET MVC with a Sitefinity CMS implementation. Namely, controllers are interpreted as widgets, so you can build Sitefinity CMS widgets from controllers and have more than one controller within a page. For more information, see MVC modes.
- Directly register MVC code as Sitefinity CMS widgets
You can directly integrate your MVC code (models, views, and controllers) by adding a simple attribute to register your controller, so it becomes available to end users to place onto pages using drag and drop. You can also work in a hybrid development environment, where your WebForms controls and MVC widgets can live together.
- Full Razor support
The MVC engine in Sitefinity CMS gives you full control over markup that your custom widgets generate, including full Razor support. You can build your views by using various template engines and, in addition, use Kendo UI framework.
- API that works for model binding in Sitefinity CMS
ASP.NET MVC exposes an API that allows you to easily perform any operation to any object controlled by the system, therefore allowing you to meet any user experience, functional, or integration requirement. In addition, the majority of the API methods work seamlessly with LINQ and return objects and collections that automatically bind to your Razor views.
- Control over routing
Sitefinity CMS works with the MVC routing engine, which provides rich features that allow you to control the URL structure of any resource out of the box. In the same time, you can use the convention-based routing within your controllers. In case you also need control over custom routes, you have full access to the Route Table.
- Dynamic data and dynamic content types
Sitefinity CMS Module Builder enables you to instantly create a data layer for any scenario. For any other content type requirement, all you need to do is define the metafields that you need and Sitefinity CMS builds the content type and automatically provides the full infrastructure - back-end screens with media fields, taxonomy fields, many-to-many relationships and so on. In addition, Sitefinity CMS exposes the full API, so you can use it in your MVC controllers
MVC development considerations
Before you start working with ASP.NET MVC in Sitefinity CMS, take a look at the following common questions regarding MVC:
For more information about the differences between the two models, see For developers: ASP.NET MVC or Web forms.
|Is Sitefinity CMS rewritten in ASP.NET MVC?
|No. Sitefinity CMS only supports ASP.NET MVC controllers and views but the CMS itself still works with WebForms.
|Will Sitefinity CMS continue to support the WebForms model?
|Yes. You can can continue working with everything you are already using with the WebForms model.
|What functionality is not supported when working in pure MVC mode?
|Forums module and Ecommerce modules are not supported.
: To make sure you are working with the accurate ASP.NET MVC version, check System requirements.
Sitefinity CMS supports just the Razor view engine and C# for ASP.NET MVC views. You can, however, write WebForms controls with ASCX markup, but all ASP.NET MVC views must use Razor and C#.
For more information about the three ASP.NET MVC modes and how you can work with them, see For developers: MVC modes