Why can't I use the C # syntax in the Inherits attribute for a private shared, but the CLR syntax is fine

The following CLR syntax works fine on 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 that I do not use ASP.NET MVC, but this works fine when using System.Web.Mvc.ViewPage<> from ASP.NET MVC.

My MyBasePage as follows:

 public class MyBasePage<TModel> : Page where TModel : class { public TModel Model { get { return (TModel)HttpContext.Current.Items["model"]; } } } 
+4
source share
1 answer

This will help you find out about the exception you are getting, but I suspect that the problem is that the base classes of the shared pages are not directly supported by ASP.net. This is achieved in MVC using a bit of hacking.

You can repeat this hack yourself if you use web forms, this should help:

Generic Inherited ViewPage <> and New Property

+2
source

Source: https://habr.com/ru/post/1335681/


All Articles