17

I have followed the answers provided by very similar posts as you will see in the step by step listed below.

I still have the same error message "does not inherit from 'System.Web.WebPages.WebPage'"

Overview

I am learning from John Papa's "Single Page Apps with HTML5, Web API, Knockout and jQuery" on Pluralsight. The course outlines building an application called "Code Camper". The example MVC4 SPA creates a root view called "index.cshtml". where a series of @RenderPage calls are made. This application runs fine on my development machine. However, if i try to create from scratch a MVC4 SPA with a root view.cshtml I always get the error "does not inherit from 'System.Web.WebPages.WebPage"

Step by Step

Download here.

1.Create a new MVC4 Internet Project called "MVC4RootView"

2.In the root of the project, create a RootView.cshtml view.

@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title></title>
</head>
<body>
    <div>
            @RenderPage("Views/Partial1.cshtml")
    </div>
</body>
</html>

3.Added a “~/Views/Partial1.cshtml” with just a simple div

<div>Hello from Partial 1</div>

4.Modified root Web.Config webpages:Enabled to true.

<add key="webpages:Enabled" value="true" />

5.Added system.web.webPages.razor to root Web.config

<system.web.webPages.razor>
  <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
  <pages pageBaseType="System.Web.Mvc.WebViewPage">
    <namespaces>
      <add namespace="System.Web.Mvc" />
      <add namespace="System.Web.Mvc.Ajax" />
      <add namespace="System.Web.Mvc.Html" />
      <add namespace="System.Web.Optimization"/>
      <add namespace="System.Web.Routing" />
    </namespaces>
  </pages>
</system.web.webPages.razor>

6.Added sectionGroup name="system.web.webPages.razor" to configSections of root web.config

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

7.Set RootView.cshtml as Start Page

8.Run and get the following error: "Type 'ASP._Page_RootView_cshtml' does not inherit from 'System.Web.WebPages.WebPage'.

I am at a loss of how to fix this. The Code Camper code works fine. I have compared line by line and see no differences in the code that would prevent from working.

Thoughts? Dan

3 Answers 3

23

Remove the web.config from your Views folder.

As you're including Partial1.cshtml from that folder, it is also including the web.config from within there. And that web.config is saying that all pages must inherit from WebViewPage.

Sign up to request clarification or add additional context in comments.

4 Comments

I did as you suggested and i still get the same error. All i have in my "View" folder now is the PartialView1.cshtml. I uploaded my changes here. skydrive.live.com/…
Oh... try to also remove the sections you added to your root web.config in your points 5. and 6.
Works now. Awesome and much appreciated!!
This rendered all my views rife with syntax errors. This file is apparently crucial.
3

I am a beginner to this, but one thing I did not realise is that cshtml pages are served through a controller, rather than by loading them directly.

In combination with the above, I also had to set the following key to false in the web.config file:

<add key="webpages:Enabled" value="false" />

1 Comment

Yep, this solved the issue for me. I wasn't using any C# in my view, so I changed it to a plain HTML file and now it works like a charm.
1

Do not delete the webconfig, is a very important file in your views!!!

Instead, do this:

Enable "View all Files" in the web project that is failing, and search for a file that seems correct but is not included in visual studio, and delete it. If it fails in your deployment folder, try to clean the folder as well, and re-deploy the site, you might have unnecesary files that might cause the same problem.

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

Hope it helps, let me know if this solve your problem as well.

1 Comment

Deleting the _ViewStart.cshtml resolved the issue for me. Thanks @Yogurtu

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.