The view must derive from WebViewPage, or WebViewPage<TModel>. (The view at ‘~/Views/home/index.cshtml’ must derive from WebViewPage, or WebViewPage<TModel>.)

I am writing this blog to help you understand the following scenario which you can see sometime while working on the ASP.NET MVC website. You are prone to get this error message if you are using ASP.NET Razor view syntax and specifically

not using the Visual Studio provided template to develop an ASP.NET MVC website or you have removed some files while customizing the template. Let’s try to understand this scenario.


The view at '~/Views/home/index.cshtml' must derive from WebViewPage, or WebViewPage<TModel>.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidOperationException: The view at '~/Views/home/index.cshtml' must derive from WebViewPage, or WebViewPage<TModel>. 



To easily understand this issue, we need to understand the WebViewPage class first. Here is the MSDN documentation which says “WebViewPage class represents the properties and methods that are needed in order to render a view that uses ASP.NET Razor syntax.”


So since we know that this is required component to get Razor syntax working, we need to find out the solution now. Easiest solution can be #1 given following and which is as per the error message says, view must derive from WebViewPage.


Solution 1.

Add following line on top of your cshtml file.

@inherits System.Web.Mvc.WebViewPage


You must be wondering now thinking that views in ASP.NET MVC templates do not have this line on top of the cshtml file? So let’s see the second solution.

Solution 2.

Add a web.config file  and specify the same setting for all the views. This  is the minimum required code in this configuration file to get rid of this error message.

<?xml version="1.0"?>
    <sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, 
                  System.Web.WebPages.Razor, Version=, Culture=neutral,PublicKeyToken=31BF3856AD364E35">
      <section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, 
               Version=, Culture=neutral,PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
      <section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor,
               Version=, Culture=neutral,PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
    <pages pageBaseType="System.Web.Mvc.WebViewPage" ></pages>

Actual setting required is pageBaseType="System.Web.Mvc.WebViewPage". Other text is only required to define the tags.


If you will create an ASP.NET MVC website using the Visual Studio provided default templates, you can see that Views folder already contains this web.config file. However, this file contains a lot of other required configuration as well.



Please let me know the feedback or concerns.



Comments (16)
  1. Durgesh says:

    Nice one thanks a lot Gaurav

  2. Max says:

    Helped me, thanks! Although i had to update the assembly versions to reflect the current versions i used in my project.

  3. Clem says:

    Is there a resolution to this yet?  Even with the section included in the web.config. the error is still thrown.

  4. Rizwan says:

    i have configured my View/Web..config with same configuration that you discussed in section 2 but i am still facing same issue… please guide me

  5. programmerwoman says:

    Unfortunatelly, There is no solution for me 🙁

  6. Amresh says:


    I am also facing the same issue but the mention solutions are not working for me. Please suggest me if i can try somethings additional to resolve this.

    I am using VS 2013, with MVC 4.5.

    1. Jacek says:

      I was also facing with this problem and above solution did not helped me but i fixed it in other way.
      I opened webcofig file located in root folder and change key:


      No other actions were required. Maybe it will help You. Good luck.

  7. Shrikant says:

    Its wonderful articles, thanks issue my resovled. please send you contact mail id so i can send my mvc problems

    1. larrybud says:

      you think this guy is here to solve all your mvc problems? lol

  8. ravindra says:

    Nice , it’s resolved my issue , thanks Gaurav

  9. pavithra velagapudi says:

    Great article. Really helped me,. Thanks

  10. Leo says:

    Thanks it works

  11. siva says:

    Nice articles ,thanks issue my resolved.

    1. Gaurav K Arya says:

      Thank you everyone. Good to know that article helped many.

  12. Ayaan Khan says:

    Description: The application attempted to perform an operation not allowed by the security policy. To grant this application the required permission please contact your system administrator or change the application’s trust level in the configuration file.

    System.Security.SecurityException: Request for the permission of type ‘System.Security.Permissions.SecurityPermission, mscorlib, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089’ failed.

    I am also facing the same issue but the mention solutions are not working for me. Please suggest me if i can try somethings additional to resolve this. i’m using vs15 mvc5

    1. Ayan,

      Your issue is not related to the one addressed here. Please refer following article for your issue FIX: How to resolve Security Exception (ASP.NET)?


Comments are closed.

Skip to main content