Change the base class of a razor view in the view code
asp.net-mvc-3, asp.net-mvc-4, c#, razor
Solution
You can change the base class in Razor with the `@inherits` keyword, your base classes just need to derive from `System.Web.Mvc.WebViewPage`.
So your sample:
`<%@ Page Language="C#" Inherits="Test.Myproject.Web.Mvc.ViewBase" %>`
Will be
`@inherits Test.Myproject.Web.Mvc.ViewBase`
Where
public class Test.Myproject.Web.Mvc.ViewBase : System.Web.Mvc.WebViewPage
{
}
Problem
Note that this is not a duplicated question. I know we can specify a base view type in the razor section of views/web.config. But I want my view1,view2 inherit from baseviewA, and the view3,view4 inherit from baseviewB. In razor how can I do this like that in ASPX engine: ``` <%@ Page Language="C#" Inherits="Test.Myproject.Web.Mvc.ViewBase" %> <%@ Control Language="C#" Inherits="Test.Myproject.Web.Mvc.PartialViewBase" %> ``` EDIT I don't care about models. In my question baseviewA and baseviewB are totally different classes.