alkampfer on April 5th, 2009

First of all thanks to Andrea Balducci that gave me this solution. I have a asp.net application where I enabled Asp.Net mvc following a link in the web. Everything works well until I try to use Strongly Typed View. When I try to have a page that inherits from ViewPage<T> where T is one of my model the system gave me an error of type

Could not load type ‘System.Web.Mvc.ViewPage<…>

In a asp.net site created with the wizard everything works ok. I check both web.config to be sure that actually I did not forgot anything, then I stumble across this post. Basically I need to modify Page directive of my web config in this way

<pages
     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">

I really do not understand why the site created with the asp.net wizard works because it does not have this directive, then Andrea told me to chek the View directory, because it has a dedicated web.config. Here is the solution. The view directory must contains a web.config like this

<?xml version="1.0"?>
<configuration>
   <system.web>
      <httpHandlers>
         <add path="*" verb="*"
             type="System.Web.HttpNotFoundHandler"/>
      </httpHandlers>

      <!--
        Enabling request validation in view pages would cause validation to occur
        after the input has already been processed by the controller. By default
        MVC performs request validation before a controller processes the input.
        To change this behavior apply the ValidateInputAttribute to a
        controller or action.
    -->
      <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>
   </system.web>

   <system.webServer>
      <validation validateIntegratedModeConfiguration="false"/>
      <handlers>
         <remove name="BlockViewHandler"/>
         <add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler"/>
      </handlers>
   </system.webServer>
</configuration>

Thanks again to Andrea for the solution.

alk.

Tags:

kick it on DotNetKicks.com

12 Responses to “Could not load type ‘System.Web.Mvc.ViewPage<..<>’”

  1. i had the same issue upgrading from preview5 to Rc1, so i knew where to look for ;)

  2. Thanks for the post. I’m currently trying to mix ASP .NET Web Forms and MVC, by placing ViewPages on ordinary MasterPage. So this worked. :P

  3. I think that actually the best approach is using both webform and mvc in the same site. Having the powerful RAD approach of webforms can be really useful to realize backoffice pages, leaving mvc and client side rendering for the public part of the site.
    Moreover you can obtain a good separation from logic and view even with webforms, if you isolate all of your logic into services and then access those services, even with the objectDataSource, you can reach a good testability without MVC.

    Surely, MVC structured pages are more testable and moreover MVC pattern forces you to separate logic and view, and I really prefer full control over html that you cannot have in webform enviroments.

    Alk.

  4. Thanks for this post, was debugging for so long :-(

  5. Thanks a lot, i spend a long time to find solution for this error. You help me to save a lot time.

  6. Thank you!! I was about to strangle somebody.

  7. I too had this problem for the same reason (integrating into an existing ASP.NET site) Found the problem at
    http://forums.asp.net/t/1378448.aspx

    You need to look at the Web.config that the normal MVC project puts in the VIEWS folder – always was puzzled by that.

    Dave

  8. I’m trying to run MVC in a web site project and was missing that Views web.config file. Thanks!

  9. worked perfectly! thank you!

  10. THANKS! :) Had exactly the same problem and this of course solved it :)

  11. Thanks! Had removed sub folders and my publish didn’t copy the config files (so no overwrites). Didn’t realize there was one hidden! :D

Trackbacks/Pingbacks

  1. Topics about Culture » Could not load type ‘System.Web.Mvc.ViewPage<..’