.netasp.net-mvcrazor

ASP.NET MVC - Forcing custom base class for Razor (cshtml) files


I'm currently using this syntax to specify a custom Razor page base class and model type:

@inherits MyWebViewPage<MyModel>

Newer builds of Razor support a new directive to simplify this code:

@model MyModel

I'd like to use this but I can't find a way to make it work with my custom base class. Is there a way to specify this at a global level for my site?


Solution

  • In views/web.config modify

    <pages pageBaseType="System.Web.Mvc.WebViewPage"> 
    

    to your class