Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 935
Drew Noakes Avatar asked Feb 08 '11 14:02

Drew Noakes


2 Answers

In views/web.config modify

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

to your class

like image 85
Lukáš Novotný Avatar answered Nov 05 '22 15:11

Lukáš Novotný


Tried to specify this in Views/Web.config?

<system.web.webPages.razor>
    <pages pageBaseType="MyUberCustomBaseClass">
    </pages>
  </system.web.webPages.razor>
like image 26
Arnis Lapsa Avatar answered Nov 05 '22 14:11

Arnis Lapsa