I'm working on creating a new base class for an asp.net app in order to create my own version of a strongly typed view from MVC. The app itself is NOT a MVC app though. Below is the basis of my custom class.
public class BasePage<T> : Page where T : IPageInfo
{
public BasePage()
{
this.MyPageInfo = IoC.GetInstance<IPageInfo>(); //pseudo-code to populate a property.
}
}
When I add a new WebForm page to my application, I change the "inherits" attribute of the Page directive to point to this BasePage class instead of the typical code-behind class in the same manner as ASP.Net MVC strongly typed views. Below is an example of the page directive.
<%@ Page language="C#" inherits="MyApp.Core.BasePage<MyApp.Content.Search>"%>
In the above directi开发者_如何转开发ve, MyApp.Content.Search class implements the IPageInfo interface that the BasePage needs to satisfy the generic type constraint.
Everything compiles fine but when I browse to the page I get the error Could Not Load Type
. I cracked open the MVC 2 assembly to look at how ViewPage was done and it appears to be the same basic structure. I looked around the web and the general recommendation for this error with MVC was to remove and readd the reference to MVC. This would be great if I was using MVC; however both my BasePage class and my Search classes are in the same assembly. I have been using fully qualified names (as shown) as well.
Anyone have any idea on what I could attempt to get this to work?
Thanks
The magic which maps <%@ Page language="C#" inherits="MyApp.Core.BasePage<MyApp.Content.Search>"%>
to MyApp.Core.BasePage was introduced with ASP.NET MVC.
You can check the implementation of System.Web.Mvc.ViewTypeParserFilter:
<pages
validateRequest="false"
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">
<controls>
<add assembly="System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" namespace="System.Web.Mvc" tagPrefix="mvc" />
</controls>
</pages>
精彩评论