New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

The Community Blog is a personal opinion of community members and by no means the official standpoint of DNN Corp or DNN Platform. This is a place to express personal thoughts about DNNPlatform, the community and its ecosystem. Do you have useful information that you would like to share with the DNN Community in a featured article or blog? If so, please contact .

The use of the Community Blog is covered by our Community Blog Guidelines - please read before commenting or posting.

Developing Modules for DotNetNuke using ASP.NET MVC - Part 1, Introduction

This post is cross-posted from my personal blog.

Last week, shaun posted a blog in which he discussed whether DotNetNuke (DNN) should be rewritten in ASP.NET MVC.  This blog created quite a stir, both within the DotNetNuke Community and within the ASP.NET Community as a whole. 

In a comment that I added to shaun’s post I suggested that the debate should not be over whether DNN should be rewritten in ASP.NET MVC (or any other framework that may come in the future), the discussion should be on “How can we enable developers to use the ASP.NET Technologies of their choice when developing extensions for DNN.”  After all, if we rewrite DNN in MVC we effectively lock out WebForm developers.

Thanks to an idea from my son Andrew (much of what I used in this work was from his Maverick project on codeplex) I have been able the create a Framework that sits on top of DotNetNuke (and System.Web.MVC) and allows modules to be created using the ASP.NET MVC Framework (DotNetNuke.Web.Mvc).

In this article I will review how – using this add-on layer we can go about creating a simple ASP.NET MVC module.  First, add an ASP.NET MVC Application to your Visual Studio solution. (See Figure 1 below)

Figure 1 – Add a new MVC Web Application in the Desktop Modules folder called MVC_Test


Note that the location of the project is in the DesktopModules folder of our test website.  This is exactly the same process we would use to add a WAP (Web Application Project) style module. Figure 2 below shows the Solution Explorer after adding this project.

Figure 2 – The new Project in Solution Explorer


Before we go any further – we should prove to ourselves that this is a valid ASP.NET MVC Web Application, by selecting the Default.aspx file, and selecting View in Browser from the Context menu (see Figure 3 below)

Figure 3 – Browsing to the site demonstrates that this is a valid ASP.NET MVC Application


So now we have an MVC Application, how do we make it run as a Module in our DotNetNuke website?  First we need to add a new class to our project – MVC_TestApplication.cs (see Figure 4).

Figure 4 – Add a new class MVC_TestApplication to the root of the Application





And we need to add references to our DotNetNuke Library project and to the new DotNetNuke.Web.Mvc project (see Figure 5)

Figure 5 – Add references to the DotNetNuke Library and the new DotNetNuke.Web.Mvc project


When we have done that we need to open the new class we added and add some very simple code.

Listing 1 – The MVC_TestApplication class

   1:  using System.Web.Routing;
   2:  using DotNetNuke.Web.Mvc;
   3:  using DotNetNuke.Web.Mvc.Routing;
   5:  namespace MVC_Test
   6:  {
   7:      public class MVC_TestApplication : MvcModuleApplication 
   8:      {
   9:          protected override string FolderPath 
  10:          {
  11:              get { return "MVC_Test"; }
  12:          }
  14:          protected override void Init() 
  15:          {
  16:              base.Init();
  17:              RegisterRoutes(Routes);
  18:          }
  20:          private static void RegisterRoutes(RouteCollection routes) 
  21:          {
  22:              routes.RegisterDefaultRoute("MVC_Test.Controllers");
  23:          }
  24:      }
  25:  }

The most important thing to note is that this class inherits from MvcModuleApplication, a new base class in the new DotNetNuke.Web.Mvc project.  The Init method allows us to register any routes that our MVC Module Application will need and the FolderPath property tells the DotNetNuke.Web.Mvc project where our Views are located.  Finally we need to make a very small change to the default View (Listing 2).

Listing 2 – Index.aspx

   1:  <%@ Page Language="C#" MasterPageFile="../Shared/Site.Master" 
Inherits="System.Web.Mvc.ViewPage" %>
   3:  <asp:Content ID="indexTitle" ContentPlaceHolderID="TitleContent" runat="server">
   4:      Home Page
   5:  asp:Content>
   7:  <asp:Content ID="indexContent" ContentPlaceHolderID="MainContent" runat="server">
   8:      <h2><%= Html.Encode(ViewData["Message"]) %>h2>
   9:      <p>
  10:          To learn more about ASP.NET MVC visit <a href= 
                               title="ASP.NET MVC Website">>.
  11:      p>
  12:  asp:Content>

If you blink you won’t see the change. 

The change is to the reference to the MasterPageFile – the value of the attribute is changed from “~/Views/Shared/Site.Master” to “../Views/Shared/Site.Master”.  The reference points to the same file – but the original reference assumes that the Views folder is at the root of the IIS Application – as a module it is actually at ~/DesktopModules/MVC_Test/Views”.  By making the reference relative it will work in both scenarios.

Next we need to create our Module Extension.  This is done in much the same way as we do today, the only difference being that when we register the Module Control we use the Namespace for the new class that we added – MVC_Test.MVC_TestApplication (See Figure 6 below).  Since version 5.0, DNN has allowed module controls to be server controls and ultimately our new MVC_TestApplication class inherits from Control.

Figure 6 – Add the MVC_TestApplication as the Source for the Default Module Control


Finally build our new MV Module Application and copy the assembly from the bin folder of the project to the bin folder of the Website.

We are now ready to see if everything works.  Add a new Page and add the newly registered Module to the Page and “hey presto” we get a Module that looks like the MVC Application (See Figure 7 below)

Figure 7 – Add the Module to the Page


The really cool thing is that we can still browse to the site (as an MVC Application) by selecting the Default.aspx page, and selecting View in Browser from the context menu, as we did in Figure 3 above.


In summary I have demonstrated in this article, that using ASP.NET MVC for Module Development is a possibility.  There still are a number of issues to resolve however, including, but not limited to:

  1. Handling routes other than the default route.
  2. Do the Html Helpers in ASP.NET MVC still work? and if not how can we make them work?
  3. As Webforms allows only one Form tag which is defined in the base page -Default.aspx -how do we handle Forms in an MVC Module.
  4. Issues around the use of Master pages and styles, and DNN skinning – we can solve this by removing the dependency on Master pages which is not a requirement of ASP.NET MVC.

I don’t expect any of these to be show-stoppers, but much more work still needs to be done.  In future blogs, I will describe how what I describe in this article was done and report on my attempts to resolve the remaining issues.


Sunil Kumar
Sunil Kumar Tuesday, January 21, 2014 8:26 AM (link)
Sunil Kumar
Hi Charles, i wanted to give it a try. Can you please suggest me from where, i can get the Dotnetnuke.Library.dll and the Dotnetnuke.Web.mvc.dll ?
Sunil Kumar Wednesday, January 22, 2014 5:27 AM (link)
Mahatab Uddin

I am new in DNN but a professional .NET developer.
I am not finding the figure 6 (Edit Module Control) that you mentioned in this post.
I am using 7.0.2.
Will you please let me know from which screen, i can go to this screen.

Thanks and appreciated.
Mahatab Uddin Thursday, January 23, 2014 1:08 AM (link)
Avinash Malhotra
Where can I download DotnetNuke.Web.Mvc from?
Avinash Malhotra Friday, September 5, 2014 4:53 AM (link)
Charles Nurse
This older version of the Maverick project is no longer available. A newer version will be made available soon.
Charles Nurse Saturday, September 6, 2014 5:15 PM (link)

Comment Form

Only registered users may post comments.


Aderson Oliveira (22)
Alec Whittington (11)
Alessandra Daniels (3)
Alex Shirley (10)
Andrew Hoefling (3)
Andrew Nurse (30)
Andy Tryba (1)
Anthony Glenwright (5)
Antonio Chagoury (28)
Ash Prasad (37)
Ben Schmidt (1)
Benjamin Hermann (25)
Benoit Sarton (9)
Beth Firebaugh (12)
Bill Walker (36)
Bob Kruger (5)
Bogdan Litescu (1)
Brian Dukes (2)
Brice Snow (1)
Bruce Chapman (20)
Bryan Andrews (1)
cathal connolly (55)
Charles Nurse (163)
Chris Hammond (213)
Chris Paterra (55)
Clint Patterson (108)
Cuong Dang (21)
Daniel Bartholomew (2)
Daniel Mettler (181)
Daniel Valadas (48)
Dave Buckner (2)
David Poindexter (12)
David Rodriguez (3)
Dennis Shiao (1)
Doug Howell (11)
Erik van Ballegoij (30)
Ernst Peter Tamminga (80)
Francisco Perez Andres (17)
Geoff Barlow (12)
George Alatrash (12)
Gifford Watkins (3)
Gilles Le Pigocher (3)
Ian Robinson (7)
Israel Martinez (17)
Jan Blomquist (2)
Jan Jonas (3)
Jaspreet Bhatia (1)
Jenni Merrifield (6)
Joe Brinkman (274)
John Mitchell (1)
Jon Henning (14)
Jonathan Sheely (4)
Jordan Coopersmith (1)
Joseph Craig (2)
Kan Ma (1)
Keivan Beigi (3)
Kelly Ford (4)
Ken Grierson (10)
Kevin Schreiner (6)
Leigh Pointer (31)
Lorraine Young (60)
Malik Khan (1)
Matt Rutledge (2)
Matthias Schlomann (16)
Mauricio Márquez (5)
Michael Doxsey (7)
Michael Tobisch (3)
Michael Washington (202)
Miguel Gatmaytan (3)
Mike Horton (19)
Mitchel Sellers (40)
Nathan Rover (3)
Navin V Nagiah (14)
Néstor Sánchez (31)
Nik Kalyani (14)
Oliver Hine (1)
Patricio F. Salinas (1)
Patrick Ryan (1)
Peter Donker (54)
Philip Beadle (135)
Philipp Becker (4)
Richard Dumas (22)
Robert J Collins (5)
Roger Selwyn (8)
Ruben Lopez (1)
Ryan Martinez (1)
Sacha Trauwaen (1)
Salar Golestanian (4)
Sanjay Mehrotra (9)
Scott McCulloch (1)
Scott Schlesier (11)
Scott Wilkinson (3)
Scott Willhite (97)
Sebastian Leupold (80)
Shaun Walker (237)
Shawn Mehaffie (17)
Stefan Cullmann (12)
Stefan Kamphuis (12)
Steve Fabian (31)
Steven Fisher (1)
Tony Henrich (3)
Torsten Weggen (3)
Tycho de Waard (4)
Vicenç Masanas (27)
Vincent Nguyen (3)
Vitaly Kozadayev (6)
Will Morgenweck (40)
Will Strohl (180)
William Severance (5)
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out