The type "ASP._Page_index_cshtml" is not inherited from "System.Web.WebPages.WebPage"

I get:

The type "ASP._Page_index_cshtml" is not inherited from "System.Web.WebPages.WebPage".

when i look at the index.cshtml file. It is very simple:

@using System.Web.Optimization @inherits System.Web.Mvc.WebViewPage <!DOCTYPE html> <html class="no-js" lang="en"> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width"> <title>Hello World</title> @Styles.Render("~/Content/css", "~/Content/themes/base/css") @Scripts.Render("~/bundles/modernizr") </head> <body> @Scripts.Render( "~/bundles/jquery", "~/bundles/jqueryui" ) </body> </html> 

my index.cshtml file is outside the Views folder, if that matters at all.

+9
source share
9 answers

I just had to delete: @inherits System.Web.Mvc.WebViewPage

It seems that during the reorganization of my project, I had an error inserting folders.

+3
source

Do not delete inheritance, this may be required and may lead to other problems in the future.

Instead, try the following:

Turn on “View all files” in a web project that doesn’t work, and find the file that seems correct but is not included in the visual studio, and delete it. If it does not work in your deployment folder, try also to clear the folder and redeploy the site, you may have unnecessary files that may cause the same problem.

In my case, in the root of webproject I had an extra copy of _ViewStart.cshtml (excluded from the project), I deleted this file and did the trick.

Hope this helps, let me know if this also solves your problem.

+2
source

I change the cshtml line to:

 Layout = "~/Views/_ViewStart.cshtml"; 

to

 Layout = "~/Views/Shared/_Layout.cshtml"; 

since _ViewStart.cshtml contains only this line of code. The layout file was needed because it contains client side script validation.

It also worked when I deleted the line, but I prefer to include _Layout.cshtml .

+1
source

Perhaps an earlier version of System.Web.WebPages.dll is loaded into memory and tries to pass your cshtml page to the version of the WebPages class from this DLL.

To check this, try looking at which http modules are currently registered:

 var allModules = HttpContext.Current.ApplicationInstance.Modules; for( int i = 0; i < allModules.Count; i++ ) { Trace(allModules.GetKey(i)); } 

In my case, it was:

 .... __DynamicModule_System.Web.WebPages.WebPageHttpModule, System.Web.WebPages, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35_bca8e05a-5746-45b0-be95-2b920b455ccf __DynamicModule_System.Web.WebPages.WebPageHttpModule, System.Web.WebPages, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35_c1a67b42-31a9-47f1-8483-9e712fabe2a7 

To fix this problem, you need to replace the older version of System.Web.WebPages.dll in the / Bin folder or some other dll files that may link to it.

0
source

Just remove _ViewStart.cshtml and add again.

0
source

No need to take stress. Just follow the two main steps.

  • Delete _ViewStart.cshtml
  • Make a comment on the comment. Means for the following expression in the index representation:

     Layout = "~/Views/_ViewStart.cshtml"; 

    and mark it as a comment:

     //Layout = "~/Views/_ViewStart.cshtml"; 
0
source

What worked for me to add ...

 @inherits System.Web.Mvc.ViewStartPage 

... back to top _ViewStart.cshtml .

I think the reason this worked for me was because of my ~/Views/Web.config file. In it, I placed the following block to avoid a lot of @inherits calls for my views ...

 <configuration> <system.web.webPages.razor> <pages pageBaseType="System.Web.Mvc.WebViewPage"> <!-- Notice pageBaseType --> ... </pages> </system.web.webPages.razor> </configuration> 

I think it is the _ViewStart.cshtml razor mechanism that all views, including _ViewStart.cshtml should be of type System.Web.Mvc.WebViewPage . This is not the same type as System.Web.Mvc.ViewSTartPage and therefore an error. Putting @inherits System.Web.Mvc.ViewStartPage at the beginning of _ViewStart.cshtml explicitly indicates the required type for _ViewStart.cshtml .

0
source

Why are you trying to go directly to the view? And why is it not in the views folder?

To get the Hello World base page, you first want to create a controller called HomeController.cs :

 using System.Web.Mvc; public class HomeController : Controller { public ActionResult Index() { return View(); } } 

Then create the file /Views/Home/Index.cshtml and put your markup in it. You may also need to add:

 @{ Layout = null; } 

at the top of the page, since it doesn't seem like you're using the main page.

As a side note, all of this assumes that you did not screw up your default routing.

-one
source

Delete the web.config file from the Views folder.

Since you include Partial1.cshtml from this folder, it also includes web.config from the inside. And this web.config says that all pages should inherit from WebViewPage.

-4
source

All Articles