Integrating ASP.NET MVC framework with AxCMS.net

ASP.NET MVC Framework is based on the Model-View-Controller architectural pattern, separating the data access, business logic and presentation using the routing capabilities of ASP.NET.

The main benefits of using ASP.NET MVC Framework are:

  • Friendly URL's which are intuitive to use (you can navigate the site by just changing URL or removing it's parts)
  • Clear separation of concerns ( you always know where to put your Business, Data Access, and Presentation logic)
  • Greater control over HTML output in MVC Views than in WebForms ( which in turn, gives you easier integration with JavaScript)
  • Test-Driven Development ( With ASP.NET MVC Framework it's easy to test controller classes without the need of emulating .aspx pages like in unit testing for Web Forms)

It is a different paradigm of developing with ASP.NET from Web Forms, instead of basing user interaction directly with .aspx pages with code-behind, Postback, ViewState, events, you create a set of routing rules which will analyse the URL of user's http request and based on that information, call the Action of appropriate Controller class which will look for appropriate Model, pass data from it to  .aspx page (View) and return the parsed result in http response.  A different Action can be called for same URL based on either browser's GET or POST verb.

The main resource for starting out with ASP.NET MVC Framework is:

http://www.asp.net/mvc/

For deploying ASP.NET MVC based projects to machines without ASP.NET MVC installed, MVC specific dll’s can be extracted to be shipped with your project:

http://haacked.com/archive/2008/11/03/bin-deploy-aspnetmvc.aspx

Using ASP.NET MVC Framework in context of AxCMS.net

It is possible to enhance your website with functionalities based on ASP.NET MVC routing engine, that way you will be able to develop Controller and Model classes (Model tables can be placed inside the CMS Live database of your project) inside the YourProject.BL project and have GUI editing capabilities of AxCMS.net for Views, with the benefits that AxCMS.net offers like user management, content management, etc. on backend.

Developing Controllers and Models

Create Controllers directory in YourProject.BL and place your classes derived from System.Web.Mvc.Controller there. By convention, Controller class must be named ClassNameController, with Controller as last part of name.

You can place Models also in YourProject.BL project.

Models are representing both Business Logic and Data Access in MVC, so you may want to further separate them and implement the Data Access logic through web services.

Developing MVC View Templates

View pages can be based on normal templates with slight difference:
To have access to ViewData and HtmlHelper classes, template should inherit from:

System.Web.Mvc.ViewPage
( or strongly typed System.Web.Mvc.ViewPage<ModelClass> )

You can create pages based on these templates as usual, to follow ASP.NET MVC convention of no code-behind you should only put only code for parsing entity(Model) fields there and use static controls that render to inline code when published.

Developing static elements for View Pages

It is possible to develop dynamic controls for View pages as well, as MVC View pages still inherit from Page, but by convention MVC View pages should not have code-behind files and render content editing logic with inline code. To follow this convention, we can make static controls that are rendered as inline code after publishing.

To have access to ViewData and HtmlHelper classes, control should inherit from:

System.Web.Mvc.ViewUserControl
( or strongly typed System.Web.Mvc.ViewUserControl<ModelClass> )

Here is the How-To FAQ and further more detailed information:

http://help.axinom.de/en_help_cms_mvc.AxCMS?ActiveID=13695
http://www.axcms.net

 

No Comments