4

The following CLR syntax works fine in my aspx page:

<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="Website.MyBasePage`1[HomePageViewModel]" %>

But this C# syntax does not:

<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="Website.MyBasePage<HomePageViewModel>" %>

Note, I am not using ASP.NET MVC, but this works fine if using System.Web.Mvc.ViewPage<> from ASP.NET MVC.

My MyBasePage looks like this:

public class MyBasePage<TModel> : Page where TModel : class {
    public TModel Model
    {
        get { return (TModel)HttpContext.Current.Items["model"]; }
    }
}
beckelmw
  • 1,722
  • 2
  • 16
  • 23

1 Answers1

2

It would help to know the exception you are getting but I would suspect that the problem is that having generic page base classes is not supported directly by ASP.net. It is achieved in MVC using a bit of a hack.

You can repeat this hack yourself if you are using Web Forms, this should help:

Generic Inherited ViewPage<> and new Property

Community
  • 1
  • 1
James Gaunt
  • 14,631
  • 2
  • 39
  • 57
  • James - Thanks for the link. I think you pinpointed exactly what is going on. For the record the error I am getting is: Parser Error Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately. Parser Error Message: Could not load type 'Website.MyBasePage'. – beckelmw Jan 15 '11 at 21:34