MVC Support

MVC Support

Model View Controller (MVC)

  • A software architecture pattern that isolates the application logic from the user interface
  • End-user interactions are routed to a Controller class instead of using the post-back model
  • Enables independent development, testing and maintenance of front-end and back-end
  • W3Schools ASP.NET MVC Tutorial

MVC Components

  • The Model manages state, business logic, persistence and notifications, usually through the use of a database
  • A View renders the Model in HTML, XHTML or another form suitable for user interaction
  • A Controller accepts input from the user, and instructs the Model to perform actions based on that input by making calls to Model Objects
  • Model Objects implement the business rules to carry out specific tasks, such as processing a user registration, then hand control over to (X)HTML-generating components such as templating engines, XML pipelines, Ajax callbacks, etc.

MVC Control Flow Cycle

  1. A user clicks a button or otherwise interacts with the user interface
  2. The controller handles the input event with a registered handler or callback
  3. The controller notifies the Model of the user action, which can result in a change of the model's state. (e.g. shopping cart update)
  4. A View queries the Model and generates updated HTML, XHTML, etc.

ASP.NET MVC Framework

  • A Microsoft web application framework based on ASP.NET that implements the MVC pattern
  • Joins the models, views, and controllers using interface-based contracts
  • Both the Razor (.cshtml and .vbhtml) and Web Forms (.aspx) view engines are supported

Sitecore Support for MVC

  • Sitecore supports both MVC 2 and MVC 3 web application projects
  • The Page Editor is designed around WebForms and doesn't work without the <form> tag

MVC 2 Projects in Sitecore

  • Download and review  Integrating an ASP.NET MVC Web Application in Sitecore CMS
  • Use the link in the first bullet to understand how to create an ASP.NET MVC 2 Web Application Project in Visual Studio
  • Use the link in the first bullet to understand how to configure the Sitecore application web.config file to support ASP.NET MVC 2
  • Assign the Sitecore CMS application pool to the same .NET Framework version used by the ASP.NET MVC application
  • Set the managed pipeline mode of the Sitecore CMS application pool to Integrated

MVC 3 Projects in Sitecore

  • Download and review Integrating an ASP.NET MVC Web Application in Sitecore CMS
  • Download and install ASP.NET MVC 3 Framework on Visual Studio 2010
  • Use the link in the first bullet to understand how to create an ASP.NET MVC 3 Web Application Project in Visual Studio
  • Use the link in the first bullet to understand how to configure the Sitecore application web.config file to support ASP.NET MVC 3
  • Assign the Sitecore CMS application pool to .NET Framework 4.0 version
  • Set the managed pipeline mode of the Sitecore CMS application pool to Integrated

MVC Guidelines for Sitecore

  • Review Sitecore MVC Crash Course for how to get an MVC project and a web application project to work together in a single Sitecore solution and how to add an existing MVC application to a SItecore solution

Sources