ASP.Net MVC4根CSHTML和"不从'System.Web.WebPages.WebPage&QUOT继承; [英] ASP.Net MVC4 Root cshtml and "does not inherit from 'System.Web.WebPages.WebPage"
问题描述
我后面很类似的帖子提供的答案,你会在一步步下列看看。
I have followed the answers provided by very similar posts as you will see in the step by step listed below.
-
<一个href=\"http://stackoverflow.com/questions/10460913/razor-view-type-does-not-inherit-from-system-web-webpages-webpage\">Razor视图类型不从'System.Web.WebPages.WebPage'继承
<一个href=\"http://iamdotnetcrazy.blogspot.com/2012/08/how-to-solve-type-asppageviewstartcshtm.html\">http://iamdotnetcrazy.blogspot.com/2012/08/how-to-solve-type-asppageviewstartcshtm.html
我仍然有相同的错误消息
I still have the same error message "does not inherit from 'System.Web.WebPages.WebPage'"
我从约翰爸爸的单页应用与HTML5,网络API,淘汰赛和jQuery关于Pluralsight学习。该课程大纲建立名为code露营的应用程序。这个例子MVC4 SPA创建了一个名为index.cshtml根视图。其中,一系列@RenderPage呼叫制成。这个应用程序运行我的机器上的罚款。但是,如果我尝试从头开始创建一个根view.cshtml我总是得到错误MVC4 SPA
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"
下载<一个href=\"https://skydrive.live.com/redir?resid=EDAFB4DBECFEE2EA!4849&authkey=!ACSorle8q0hebwY\">here.
1,创建一个新的MVC4互联网项目被称为MVC4RootView
1.Create a new MVC4 Internet Project called "MVC4RootView"
2.In项目的根目录,创建一个RootView.cshtml视图。
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一个〜/查看/ Partial1.cshtml只是一个简单的div
3.Added a "~/Views/Partial1.cshtml" with just a simple div
<div>Hello from Partial 1</div>
4.Modified根Web.config网页:启用为true
4.Modified root Web.Config webpages:Enabled to true.
<add key="webpages:Enabled" value="true" />
5.Added system.web.webPages.razor到根Web.config
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根web.config中的configSections
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起始页
7.Set RootView.cshtml as Start Page
8.Run并得到以下错误:类型ASP._Page_RootView_cshtml不从'System.Web.WebPages.WebPage'继承
8.Run and get the following error: "Type 'ASP._Page_RootView_cshtml' does not inherit from 'System.Web.WebPages.WebPage'.
我在如何解决这个问题的损失。在code坎珀code正常工作。我比较逐行并查看code,将美元,工作p $ pvent没有区别。
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.
的思考?
丹
推荐答案
删除的web.config
从查看
文件夹中。
当你包括 Partial1.cshtml
从该文件夹,它也包括来自内有web.config中。这是web.config中说,所有的页面必须从WebViewPage继承。
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.
这篇关于ASP.Net MVC4根CSHTML和&QUOT;不从'System.Web.WebPages.WebPage&QUOT继承;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!