Webforms 移植到 Razor MVC 错误

发布于 2024-11-29 13:48:23 字数 1219 浏览 1 评论 0原文

The view 'Art' or its master was not found. The following locations were searched

~/Views/Home/Art.aspx
~/Views/Home/Art.ascx
~/Views/Shared/Art.aspx
~/Views/Shared/Art.ascx

我使用 Razor View Engine 创建了视图。因此,该视图存在于 Home 文件夹下的 Views 文件夹中,名称为 Art.vbhtml

请告诉我如何告诉 Web 应用程序它需要使用 Razor View Engine

更新:

将 MVC 2.0 迁移到后使用 Razor 时出现问题MVC 3.0 RC 帮助了我,但现在它给出了这个错误......

Type 'RazorViewEngine' is not defined

尽管,视觉工作室中的智能感知正在显示它并突出显示为类名。

更新二:

Nathan Ratcliff 的回答有助于消除错误,但现在正在产生新的错误,其详细信息如下...

The view at '~/Views/Home/Art.vbhtml' must derive from WebViewPage, or WebViewPage<TModel>.

Nathan 你也能帮我解决这个问题吗?

答案摘要 对于那些后来到达这个阶段的人来说,所提供的答案足以澄清我的情况,但我想澄清一些有关答案的事情。

我必须执行以下步骤才能使 Razor 引擎在我的应用程序中运行(除了答案之外):

  • 在项目的 Views 文件夹中添加了 web.config (在 web.config 中添加了下面答案中提供的代码部分) )。
  • 在我的项目中添加了对 System.WebPages.dll 文件的引用。
The view 'Art' or its master was not found. The following locations were searched

~/Views/Home/Art.aspx
~/Views/Home/Art.ascx
~/Views/Shared/Art.aspx
~/Views/Shared/Art.ascx

I've created the view using the Razor View Engine. So, the view exists in the Views folder under the Home folder with the name Art.vbhtml

Please tell me how to tell the web application that it needs to render the views using the Razor View Engine

UPDATE:

Problem using Razor after migrating MVC 2.0 to MVC 3.0 RC helped me, but now it is giving this error...

Type 'RazorViewEngine' is not defined

although, intellisense in the visual studio is showing it and highlighting as a class name as well.

UPDATE II:

Nathan Ratcliff's answer helped in removing the error, but now the new error is producing whose details are as under...

The view at '~/Views/Home/Art.vbhtml' must derive from WebViewPage, or WebViewPage<TModel>.

Nathan can you help me on this as well?

ANSWER SUMMARY
For those, who arrive later on this stage, the answer supplied is enough to clear my situation, but I would like to clarify a few things regarding the answer.

I had to perform the following steps to make the Razor Engine running in my application(apart from the answer):

  • Added a web.config in the Views folder in the project (Added sections of code supplied in the answer below in the web.config).
  • Added a reference for the System.WebPages.dll file in my project.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浮世清欢 2024-12-06 13:48:23

确保您的 web.config 的编译部分中有此内容

<add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />

并删除旧的。

另外,www.asp.net 关于从 2.0 升级的建议 -> 3.0

http://www.asp.net/learn/whitepapers/mvc3- release-notes#upgrading

编辑:

在您的视图文件夹中,有一个 web.config (不是项目根目录下的那个)。

它有剃刀配置部分吗?

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


    <system.web.webPages.razor>
      <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=3.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.Routing" />
        </namespaces>
      </pages>
    </system.web.webPages.razor>    

Make sure you have this in the compilation section of your web.config

<add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />

and remove the old one.

Also, www.asp.net's recommendations for upgrading from 2.0 -> 3.0

http://www.asp.net/learn/whitepapers/mvc3-release-notes#upgrading

Edit:

In your views folder, there is a web.config (not the one at the root of your project).

Does it have the razor config sections?

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


    <system.web.webPages.razor>
      <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=3.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.Routing" />
        </namespaces>
      </pages>
    </system.web.webPages.razor>    
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文