Beginner’s Introduction to Sitecore MVC

Sitecore MVC is the driving force behind the Sitecore software. It was designed to expand and enhance the already present features within ASP.Net MVC. As a relatively newcomer to Sitecore, I was curious as to why individuals decided to create Sitecore MVC, rather than just use ASP.Net MVC. In this post, I wish to find the answer to that question by exploring the major differences between ASP.Net MVC and Sitecore which will explain what makes the latter so great.

ASP.NET MVC is an open source framework which implements the model–view–controller design pattern. Model is the layer that holds a base of the code and algorithmic logic. View is the layer which displays the interface that a user sees and controller is the layer that the user uses to interact with the application. The MVC pattern helps you create applications that separate the different aspects of the application while still keeping everything connected together. Due to this architecture, MVC provides an opportunity for parallel development which can give developers more power and freedom. Apart from making developing easier, the MVC pattern makes application debugging easier and more fun.

One of the biggest features of ASP.Net MVC is that it clearly divides the different areas of building a large-scale, web-based application. Areas such as input, business, and UI logic are given their own domain which greatly reduces the stress on a team. ASP.Net MVC also supports test-driven development thus removing the reliance of testing work on a web server. Another feature it offers is that the community provides an extensive library of frameworks and packages that change the game for the better. It offers detailed support for URL routing allowing you to make user and server friendly domains. The last feature is that it still maintains existing ASP.Net features which is critical for those who use it.

With these features come a lot of advantages. One advantage is that it makes development simpler since the project is separated in a model, a view, and a controller. Another is that it gives the developer full control over the behavior of their application because it does not use view or server forms. Web app requests are processed through a singular controller making everything faster. Finally for big development teams, this architecture allows a higher degree of control and consistency especially for more complex projects. Anything that you can do with MVC, you can do with Sitecore MVC. Since that is the case, what exactly does Sitecore MVC offer that that ASP.NET MVC does not?

Sitecore MVC offers native support for the model-view-controller programming model. It operates alongside ASP.Net Web Forms on a per request basis. This means that it is possible to have a website where some pages are handled by MVC and others are handled by Web Forms. So both MVC and Web Forms can be used in a single web application. A Sitecore page is assembled from components. In web forms, those components are usually in a web layout but in Sitecore MVC those are called view renderings (razor views). A view rendering represents an MVC view and you can bind as many view renderings to a page as you want, which is different from ASP.Net. The last difference is that you can also use a controller rendering where you specify a controller and a view to the return valve. Since Sitecore pages are built from components, if you have several of these controller renderings on a single page, you’ll be executing the MVC interaction several times per page load which varies from the traditional MVC practice. The following post goes into more detail on the specific protocol differences between Sitecore MVC and ASP.Net MVC: How is Sitecore MVC Different from ASP.NET MVC?

In conclusion, Sitecore MVC seems to be a compact layer of APIs that builds on the existing ASP.Net MVC framework. It gives developers more freedom and options to build web applications to their preference and that seems to be what sets Sitecore apart from the competition.

If you have any questions about Sitecore or Sitecore MVC send us an email!