本文介绍了“System.Web.WebPages.Html.HtmlHelper'不包含'ActionLink的定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先 - 我已经走遍SO 并发现有很多问题问同样的事情,虽然简单地添加<添加命名空间=System.Web.Mvc.Html/&GT ; 在我的web.config没治好这个问题...

好了,我已经开始了一个新的项目,基于模板的角SPA - 链接是在这里:

http://visualstudiogallery.msdn.microsoft.com/5af151b2-9ed2-4809-bfe8-27566bfe7d83

我已经升级了MVC 5版&安培;在的WebAPI到版本2 - 下跌与溶液中的其他项目行

现在,在SPA网站我试图使用 @ Html.ActionLink 帮手_layout页面,虽然不断收到错误 System.Web.WebPages.Html.HtmlHelper'不包含定义'ActionLink的

我相信这是所有到一些web.config配置 - 某种冲突的什么包我已经安装了,哪些是从模板的配置设置。

在具体地,该部分:

 < system.web.webPages.razor>
    <主机factoryType =System.Web.WebPages.Razor.WebRazorHostFactory,System.Web.WebPages.Razor,版本= 3.0.0.0,文化=中性公钥= 31BF3856AD364E35/>
    <页面pageBaseType =System.Web.WebPages.WebPage>
      <&命名空间GT;
        <添加命名空间=System.Web.Helpers/>
        <添加命名空间=System.Web.Mvc/>
        <添加命名空间=System.Web.Mvc.Ajax/>
        <添加命名空间=System.Web.Mvc.Html/>
        <添加命名空间=System.Web.Optimization/>
        <添加命名空间=System.Web.Routing/>
        <添加命名空间=System.Web.WebPages/>
      < /命名空间>
    < /页>
  < /system.web.webPages.razor>

如果我改变了用5版本,那么我得到错误的组件(V5)无法定位等。

我运行了关于如何解决这个矛盾的想法。

下面是从我的SPA web.config中配置部分

 < sectionGroup NAME =system.web.webPages.razorTYPE =System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup,System.Web.WebPages.Razor,版本= 3.0.0.0,文化=中性公钥= 31BF3856AD364E35>
      <节名称=主机TYPE =System.Web.WebPages.Razor.Configuration.HostSection,System.Web.WebPages.Razor,版本= 3.0.0.0,文化=中性公钥= 31BF3856AD364E35requirePermission =假 />
      <节名称=页面TYPE =System.Web.WebPages.Razor.Configuration.RazorPagesSection,System.Web.WebPages.Razor,版本= 3.0.0.0,文化=中性公钥= 31BF3856AD364E35requirePermission =假 />
    < / sectionGroup>

如果我更改版本5,我得到以下错误:

 程序集加载跟踪:下列信息有助于确定程序集System.Web.WebPages.Razor,版本5.0.0.0 =文化=中性公钥= 31bf3856ad364e35'无法加载。
=== pre-绑定状态信息===
日志:显示名称= System.Web.WebPages.Razor,版本5.0.0.0 =文化=中性公钥= 31bf3856ad364e35
 (完全指定)
日志:应用平台=文件:/// D:/Development/IS/IS/IS.TransactionDesk.SPA/
LOG:初始PrivatePath = D:\\开发\\ IS \\ IS \\ IS.TransactionDesk.SPA \\ BIN
调用汇编:(未知)。
===
日志:此绑定的默认加载上下文开始。
日志:正在使用应用程序配置文件:D:\\开发\\ IS \\ IS \\ IS.TransactionDesk.SPA \\ web.config中
日志:使用主机配置文件:C:\\用户\\达伦\\文档\\ IISEx preSS \\设置\\ aspnet.config
日志:从C使用计算机配置文件:\\ WINDOWS \\ Microsoft.NET \\框架\\ v4.0.30319 \\ CONFIG \\ machine.config中。
日志:后政策参考:System.Web.WebPages.Razor,版本5.0.0.0 =文化=中性公钥= 31bf3856ad364e35
日志:新的URL文件试图下载:/// C:/用户/达伦/应用程序数据/本地/温度/ ASP.NET临时文件/根/ 3407d437 / 8e7ba9a / System.Web.WebPages.Razor.DLL。
日志:新的URL文件试图下载:/// C:/用户/达伦/应用程序数据/本地/温度/ ASP.NET临时文件/根/ 3407d437 / 8e7ba9a / System.Web.WebPages.Razor / System.Web.WebPages .Razor.DLL。
日志:新的URL文件试图下载:/// D:/Development/IS/IS/IS.TransactionDesk.SPA/bin/System.Web.WebPages.Razor.DLL。
警告:比较程序集名称时发生不匹配:主版本
错误:未能完成组装(HR = 0x80131040)的设置。探测终止。堆栈跟踪:
[FileLoadException:未能加载文件或程序集System.Web.WebPages.Razor,版本5.0.0.0 =文化=中性公钥= 31bf3856ad364e35或它的一个依赖。找到的程序集清单定义不匹配程序集引用。 (异常来自HRESULT:0x80131040)]
   System.RuntimeTypeHandle.GetTypeByName(字符串名称,布尔throwOnError,布尔IGNORECASE,布尔reflectionOnly,StackCrawlMarkHandle stackMark,IntPtr的pPrivHostBinder,布尔loadTypeFromPartialName,ObjectHandleOnStack型)+ 0
   System.RuntimeTypeHandle.GetTypeByName(字符串名称,布尔throwOnError,布尔IGNORECASE,布尔reflectionOnly,StackCrawlMark&安培; stackMark,IntPtr的pPrivHostBinder,布尔loadTypeFromPartialName)+ 70
   System.RuntimeType.GetType(字符串的typeName,布尔throwOnError,布尔IGNORECASE,布尔reflectionOnly,StackCrawlMark&安培; stackMark)+39
   System.Type.GetType(字符串的typeName,布尔throwOnError,布尔IGNORECASE)+37
   System.Web.Compilation.BuildManager.GetType(字符串的typeName,布尔throwOnError,布尔IGNORECASE)+65
   System.Web.WebPages.Razor.WebRazorHostFactory.DefaultTypeFactory(字符串的typeName)+39
   System.Web.WebPages.Razor.WebRazorHostFactory.CreateFactory(字符串的typeName)+67
   System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKEY的关键,Func`2 valueFactory)+72
   System.Web.WebPages.Razor.WebRazorHostFactory.CreateHostFromConfigCore(RazorWebSectionGroup配置,字符串virtualPath,字符串physicalPath)313
   System.Web.WebPages.Razor.WebRazorHostFactory.CreateHostFromConfig(字符串virtualPath,字符串physicalPath)+228
   System.Web.WebPages.Razor.WebRazorHostFactory.CreateHostFromConfig(字符串virtualPath)+38
   System.Web.WebPages.Razor.RazorBuildProvider.GetHostFromConfig()+51
   System.Web.WebPages.Razor.RazorBuildProvider.CreateHost()+57
   System.Web.WebPages.Razor.RazorBuildProvider.get_Host()+56
   System.Web.WebPages.Razor.RazorBuildProvider.EnsureGenerated code()+77
   System.Web.WebPages.Razor.RazorBuildProvider.get_ codeCompilerType()+54
   System.Web.Compilation.BuildProvider.GetCompilerTypeFromBuildProvider(BuildProvider buildProvider)+59
   System.Web.Compilation.BuildProvidersCompiler.ProcessBuildProviders()+ 209
   System.Web.Compilation.BuildProvidersCompiler.PerformBuild()+30
   System.Web.Compilation.BuildManager.CompileWebFile(VirtualPath virtualPath)9881909
   System.Web.Compilation.BuildManager.GetVPathBuildResultInternal(VirtualPath virtualPath,布尔noBuild,布尔allowCrossApp,布尔allowBuildIn precompile,布尔throwIfNotFound,布尔ensureIsUpToDate)+299
   System.Web.Compilation.BuildManager.GetVPathBuildResultWithNoAssert(HttpContext的背景下,VirtualPath virtualPath,布尔noBuild,布尔allowCrossApp,布尔allowBuildIn precompile,布尔throwIfNotFound,布尔ensureIsUpToDate)+103
   System.Web.Compilation.BuildManager.GetVirtualPathObjectFactory(VirtualPath virtualPath,HttpContext的背景下,布尔allowCrossApp,布尔throwIfNotFound)+ 165
   System.Web.Compilation.BuildManager.CreateInstanceFromVirtualPath(VirtualPath virtualPath,类型requiredBaseType,HttpContext的背景下,布尔allowCrossApp)+43
   System.Web.Compilation.BuildManager.CreateInstanceFromVirtualPath(字符串virtualPath,类型requiredBaseType)+28
   System.Web.WebPages.BuildManagerWrapper.CreateInstanceOfType(字符串virtualPath)343
   System.Web.WebPages.VirtualPathFactoryExtensions.CreateInstance(IVirtualPathFactory工厂,字符串virtualPath)236
   System.Web.WebPages.VirtualPathFactoryManager.CreateInstanceOfType(字符串virtualPath)+261
   System.Web.WebPages.VirtualPathFactoryExtensions.CreateInstance(IVirtualPathFactory工厂,字符串virtualPath)+132
   System.Web.WebPages.WebPageHttpHandler.CreateFromVirtualPath(字符串virtualPath,IVirtualPathFactory virtualPathFactory)+58
   System.Web.WebPages.WebPageHttpHandler.CreateFromVirtualPath(字符串virtualPath)+59
   IS.TransactionDesk.SPA.Routing.DefaultRouteHandler.GetHttpHandler(RequestContext的RequestContext的)在d:\\开发\\ IS \\ IS \\ IS.TransactionDesk.SPA \\路径\\ DefaultRouteHandler.cs:42
   System.Web.Routing.UrlRoutingModule.PostResolveRequestCache(HttpContextBase上下文)9598252
   System.Web.Routing.UrlRoutingModule.OnApplicationPostResolveRequestCache(对象发件人,EventArgs的发送)+82
   System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()+136
   System.Web.HttpApplication.ExecuteStep(IExecutionStep一步,布尔和放大器; completedSynchronously)+69


解决方案

我与VS 2013的工作临更新2.这是我工作:


  1. 关闭Visual Studio中

  2. 删除bin和OBJ文件夹

  3. 重新打开您的解决方案,重建

  4. 在视图中没有更多的错误

BTW,没有必要改变对配置文件什么,简单的清洁和重建的解决方案是行不通的。

Firstly - I have scoured SO and found many questions asking the same thing, though simply adding <add namespace="System.Web.Mvc.Html" /> in my web.config didn't cure the issue...

Ok, so I have started a new project, based on the template Angular SPA - link is here:

http://visualstudiogallery.msdn.microsoft.com/5af151b2-9ed2-4809-bfe8-27566bfe7d83

I have upgraded the MVC to version 5 & the webApi to version 2 - to fall in line with other projects in the solution.

Now, in the _layout page of the SPA site I am trying to use the @Html.ActionLink helper, though keep getting the error 'System.Web.WebPages.Html.HtmlHelper' does not contain a definition for 'ActionLink

I am sure this is all down to some web.config configuration - some kind of conflict between what packages I have installed and what is setup in the config from the template.

In particular, this part:

<system.web.webPages.razor>
    <host factoryType="System.Web.WebPages.Razor.WebRazorHostFactory, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <pages pageBaseType="System.Web.WebPages.WebPage">
      <namespaces>
        <add namespace="System.Web.Helpers" />
        <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" />
        <add namespace="System.Web.WebPages" />
      </namespaces>
    </pages>
  </system.web.webPages.razor>

If I change this to use version 5 then I get the error that the assembly (v5) could not be located etc.

I am running out of ideas on how to resolve this conflict.

Here are the config sections from my SPA web.config

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

If I change the version to 5, I get the error below:

Assembly Load Trace: The following information can be helpful to determine why the assembly 'System.Web.WebPages.Razor, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' could not be loaded.


=== Pre-bind state information ===
LOG: DisplayName = System.Web.WebPages.Razor, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
 (Fully-specified)
LOG: Appbase = file:///D:/Development/IS/IS/IS.TransactionDesk.SPA/
LOG: Initial PrivatePath = D:\Development\IS\IS\IS.TransactionDesk.SPA\bin
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: D:\Development\IS\IS\IS.TransactionDesk.SPA\web.config
LOG: Using host configuration file: C:\Users\Darren\Documents\IISExpress\config\aspnet.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Post-policy reference: System.Web.WebPages.Razor, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
LOG: Attempting download of new URL file:///C:/Users/Darren/AppData/Local/Temp/Temporary ASP.NET Files/root/3407d437/8e7ba9a/System.Web.WebPages.Razor.DLL.
LOG: Attempting download of new URL file:///C:/Users/Darren/AppData/Local/Temp/Temporary ASP.NET Files/root/3407d437/8e7ba9a/System.Web.WebPages.Razor/System.Web.WebPages.Razor.DLL.
LOG: Attempting download of new URL file:///D:/Development/IS/IS/IS.TransactionDesk.SPA/bin/System.Web.WebPages.Razor.DLL.
WRN: Comparing the assembly name resulted in the mismatch: Major Version
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.

Stack Trace:


[FileLoadException: Could not load file or assembly 'System.Web.WebPages.Razor, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)]
   System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMarkHandle stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName, ObjectHandleOnStack type) +0
   System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName) +70
   System.RuntimeType.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark) +39
   System.Type.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase) +37
   System.Web.Compilation.BuildManager.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase) +65
   System.Web.WebPages.Razor.WebRazorHostFactory.DefaultTypeFactory(String typeName) +39
   System.Web.WebPages.Razor.WebRazorHostFactory.CreateFactory(String typeName) +67
   System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory) +72
   System.Web.WebPages.Razor.WebRazorHostFactory.CreateHostFromConfigCore(RazorWebSectionGroup config, String virtualPath, String physicalPath) +313
   System.Web.WebPages.Razor.WebRazorHostFactory.CreateHostFromConfig(String virtualPath, String physicalPath) +228
   System.Web.WebPages.Razor.WebRazorHostFactory.CreateHostFromConfig(String virtualPath) +38
   System.Web.WebPages.Razor.RazorBuildProvider.GetHostFromConfig() +51
   System.Web.WebPages.Razor.RazorBuildProvider.CreateHost() +57
   System.Web.WebPages.Razor.RazorBuildProvider.get_Host() +56
   System.Web.WebPages.Razor.RazorBuildProvider.EnsureGeneratedCode() +77
   System.Web.WebPages.Razor.RazorBuildProvider.get_CodeCompilerType() +54
   System.Web.Compilation.BuildProvider.GetCompilerTypeFromBuildProvider(BuildProvider buildProvider) +59
   System.Web.Compilation.BuildProvidersCompiler.ProcessBuildProviders() +209
   System.Web.Compilation.BuildProvidersCompiler.PerformBuild() +30
   System.Web.Compilation.BuildManager.CompileWebFile(VirtualPath virtualPath) +9881909
   System.Web.Compilation.BuildManager.GetVPathBuildResultInternal(VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile, Boolean throwIfNotFound, Boolean ensureIsUpToDate) +299
   System.Web.Compilation.BuildManager.GetVPathBuildResultWithNoAssert(HttpContext context, VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile, Boolean throwIfNotFound, Boolean ensureIsUpToDate) +103
   System.Web.Compilation.BuildManager.GetVirtualPathObjectFactory(VirtualPath virtualPath, HttpContext context, Boolean allowCrossApp, Boolean throwIfNotFound) +165
   System.Web.Compilation.BuildManager.CreateInstanceFromVirtualPath(VirtualPath virtualPath, Type requiredBaseType, HttpContext context, Boolean allowCrossApp) +43
   System.Web.Compilation.BuildManager.CreateInstanceFromVirtualPath(String virtualPath, Type requiredBaseType) +28
   System.Web.WebPages.BuildManagerWrapper.CreateInstanceOfType(String virtualPath) +343
   System.Web.WebPages.VirtualPathFactoryExtensions.CreateInstance(IVirtualPathFactory factory, String virtualPath) +236
   System.Web.WebPages.VirtualPathFactoryManager.CreateInstanceOfType(String virtualPath) +261
   System.Web.WebPages.VirtualPathFactoryExtensions.CreateInstance(IVirtualPathFactory factory, String virtualPath) +132
   System.Web.WebPages.WebPageHttpHandler.CreateFromVirtualPath(String virtualPath, IVirtualPathFactory virtualPathFactory) +58
   System.Web.WebPages.WebPageHttpHandler.CreateFromVirtualPath(String virtualPath) +59
   IS.TransactionDesk.SPA.Routing.DefaultRouteHandler.GetHttpHandler(RequestContext requestContext) in d:\Development\IS\IS\IS.TransactionDesk.SPA\Routing\DefaultRouteHandler.cs:42
   System.Web.Routing.UrlRoutingModule.PostResolveRequestCache(HttpContextBase context) +9598252
   System.Web.Routing.UrlRoutingModule.OnApplicationPostResolveRequestCache(Object sender, EventArgs e) +82
   System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +136
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +69
解决方案

I'm working with VS 2013 Pro Update 2. This is what worked for me:

  1. Close Visual Studio
  2. Delete bin and obj folders
  3. Reopen your solution and rebuild
  4. No more errors on the view

BTW there is no need to change anything on configuration files and a simple clean and rebuild solution does not work.

这篇关于“System.Web.WebPages.Html.HtmlHelper'不包含'ActionLink的定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 01:30