Tuesday, 3 February 2009

ASP.NET MVC RC1 and Areas

I just found out something today that is very important if you have implemented areas in ASP.NET MVC as per this post by Phil Haack.  With RC1, strongly typed views that do not have code behind files (as per the RC1 setup) will throw an error:

UPDATE: Parser Error Message: Could not load type 'System.Web.Mvc.ViewPage<ModelObject>'

The problem is that your view folders within each of the areas does not have a Web.config file like your root view folder.  With RC1, the Web.config file in the root folder needs to have this:

<pages validateRequest="false"
   pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
   pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
   userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
    <controls>
        <add assembly="System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" namespace="System.Web.Mvc" tagPrefix="mvc" />
    </controls>
</pages>

The simple solution is to make a Web.config file for each of the Views folders in your areas that is exactly the same as the one in your root view path.  Things will start working after that.

No comments: