If you have tried to get these two to work together, then you are probably had to deal with a lot of the same issues that I had.  A big help for getting these two to work with each other is the SharePointMVC project on CodePlex.

After downloading this sample, you have some steps that will allow you to get MVC to run underneath SharePoint.

Here is how it is setup:

  • A SharePoint Master Page contains all SharePoint styles and theme
  • A custom ASP.net page (MVCHostingPage) is based upon the SharePoint Master Page
  • MVCHostingPage contains a web control called RenderControl
  • RenderControl (and other internal classes) interrogates the current request and forwards it onto the ASP.NET MVC rendering engine.
  • A HttpHandler takes all requests to *.mvc and redirects them to the MvcHostingPage.aspx page.
  • A few things to keep in mind, the deployment instructions tell you to create a Virtual Directory for the project, if you make it an Application, you will get an error in SharePoint when you try to use the SharePoint master page because it is a cross Domain call.

    I extended the HtmlHelper class to add a Pager and after doing these steps, the Pager didn’t work correctly.  So watch out for that if you are doing this, like following the Create a Pager HTML Helper post.

    There are some other ways to get this to work so if you have had success doing this, please let me know about it.  There is also a question on stackoverflow around this with some other thoughts and suggestions.