剃刀视图没有看到System.Web.Mvc.HtmlHelper [英] Razor Views not seeing System.Web.Mvc.HtmlHelper

查看:239
本文介绍了剃刀视图没有看到System.Web.Mvc.HtmlHelper的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在升级到MVC4的过程。我按照指示在<一个href=\"http://www.asp.net/whitepapers/mvc4-release-notes#_Toc303253806\">http://www.asp.net/whitepapers/mvc4-release-notes#_Toc303253806但在我的剃刀视图和布局我有一个像

I am in the process of upgrading to MVC4. I have followed the instructions at http://www.asp.net/whitepapers/mvc4-release-notes#_Toc303253806 but in my Razor views and layouts I have errors like


  • 'System.Web.WebPages.Html.HtmlHelper'不包含一个定义
    对于BeginRouteForm',没有扩展方法'BeginRouteForm
    接受类型的第一个参数
    System.Web.WebPages.Html.HtmlHelper'可以找到(是否缺少
    使用指令或程序集引用?)

我也有这样的错误:


  • 'Viewbag'这​​个名字并不在目前的情况下存在

当我将鼠标悬停在@Html我可以看到它的类型是System.Web.WebPages.Html.HtmlHelper不System.Web.Mvc.HtmlHelper

When I hover over @Html I can see it is of type System.Web.WebPages.Html.HtmlHelper not System.Web.Mvc.HtmlHelper

不是真的知道什么其它信息相关,但这是我所在的地方:

Not really sure what other information is pertinent but this is where I am:


  • 我还没有更新的类图书馆的等等。在SLN到.NET 4.5呢。

  • 项目于VS2010创建的,但我做的迁移
    VS2012

  • 项目打开并运行与VS2012 OK,.NET 4.0,MVC 3

任何指针AP preciated。

Any pointers appreciated.

编辑:
升级到所有参考文献和文​​件,在web.config中:

All references and files in web.config upgraded to:


  • System.Web.Mvc,版本= 4.0.0.0

  • System.Web.WebPages,版本= 2.0.0.0

  • System.Web.Helpers,版本= 2.0.0.0

  • System.Web.WebPages.Razor,
    版本= 2.0.0.0

修改(2):
在我的元素/views/web.config(或/views/shared/web.config如果我尝试以下@保罗的解决方案),我从System.Web.Mvc.WebViewPage继承我自己的基本类型中,在包含库引用已更新为MVC4并转到定义带我到MVC4 DLL。

Edit(2): In my /views/web.config (or /views/shared/web.config if I try @Paul 's solution below) in the element, I have my own base type which inherits from System.Web.Mvc.WebViewPage , the references in the containing library have been updated to MVC4 and go to definition takes me to the MVC4 dll.

有没有什么这方面的改变对新版本?我看不出在发行说明有关的东西。

Has anything changed in this area on the new release? I couldn't see anything pertinent in the release notes.

推荐答案

我遇到了这个问题与Web应用程序 - 我的 .cshtml 文件已经粘在 System.Web.WebPages.WebViewPage 基类,当我需要的 System.Web.Mvc.WebViewPage 。首先,确保你的〜/查看/ web.config文件中具有正确的 pageBaseType - 在我的情况, System.Web.Mvc.WebViewPage

I ran into this issue with a Web Application - my .cshtml files got stuck on the System.Web.WebPages.WebViewPage base class when I needed the System.Web.Mvc.WebViewPage. First, ensure your ~/Views/web.config file has the correct pageBaseType - in my case, System.Web.Mvc.WebViewPage.

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

然后,重要后,有些人已经找到,如果上面来说已经不错了,这是关键的:

Then, importantly, some people have found this is key if the above is already good:


  1. 在解决方案运行干净

  2. 卸载的问题项目

  3. 删除。用户文件旁边的项目生成的Visual Studio。

  4. 刷新的各项问题的项目

  5. 生成解决方案

  1. Run a clean on the solution
  2. Unload the project with the issues
  3. Delete the .user file that Visual Studio generated next to the project.
  4. Reload the project with the issues
  5. Build the solution

对于VS2015 。用户的.sln 文件已移到 .VS 。在随后创建到的.sln 文件隐藏文件夹。然而,从下面的注释,错误消息暗示对我来说,工装使用MVC的错版完全和删除此文件夹不解决问题。据我所知,还没有一个已知的解决方案。 (对不起!)

For VS2015, the .user and .sln files have moved to the .vs hidden folder that is created next to the .sln file. However, from comments below, the error messages imply to me that the tooling is using the wrong version of MVC entirely, and deleting this folder does not fix the issue. To my knowledge, there is not a known solution. (Sorry!)

这篇关于剃刀视图没有看到System.Web.Mvc.HtmlHelper的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆