开发者

Why can't I use C# Syntax in the Inherits Attribute for a Closed Generic but CLR Syntax is fine

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
    {
   开发者_StackOverflow中文版     get { return (TModel)HttpContext.Current.Items["model"]; }
    }
}


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜