Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In ASP.NET MVC, why can't I inherit from "MyCustomView" without specifying the full type name? [duplicate]

Tags:

asp.net-mvc

In my MVC apps I normally declare a base view type that all of my views inherit from. I get a parser error when I specify Inherits="MyView" in my Page declaration, but not if I specify Inherits="MyApp.Web.Views.MyView".

Strangely enough, it works fine if I specify a strongly typed view name: Inherits="MyView<T> (where T is any valid type).

Why can I specify a strongly typed view without the full type name, but not a generic view?

My base view class is declared like this:

namespace MyApp.Web.Views {
    public class MyView : MyView<object> {
    }

    public class MyView<TModel> : ViewPage<TModel> where TModel : class {
    }
}

UPDATE: Note that I do import MyApp.Web.Views via web.config. If I did not, then the strongly typed approach (Inherits="MyView<T>") wouldn't work either.

like image 483
Seth Petry-Johnson Avatar asked Apr 21 '10 15:04

Seth Petry-Johnson


1 Answers

From another post: Here's the underlying issue: the ASP.NET page parser does not support generics as a page type

Read more here- Generic Inherited ViewPage<> and new Property

like image 89
moomi Avatar answered Oct 14 '22 07:10

moomi