I'm trying to add a View to an arbitrary folder in my MVC project (~/SomeOtherViewDirectory). This works fine until I modify the View to use be strongly typed.
Ie, if the page inherits from System.Web.Mvc.ViewPage, it compiles and runs fine, but if it inherits from System.Web.Mvc.ViewPage it does not. When I turn page compilation on, it won't compile (can't find type) otherwise it throws a runtime exception.
I'm using a custom ViewEngine -- it's just the standard WebFormsViewEngine with customized location strings for finding the View.
Funny thing about this is that the same (empt开发者_如何学Cy) page works inside the Views directory. And I can modify my ViewEngine to point to some sub-sub-sub directory of Views (say, ~/Views/This/Is/Weird/) and copy/paste the page there and everything compiles and runs fine.
WTH?
For views outside the Views folder we need to modify the web.config. If you check the web.config in the views folder, you'll notice this additional configuration, either create a new web.config in those additional folders, or add it to the root web.config file.
<pages
pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
Try that and hopefully that should sort your problem out.
精彩评论