Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
374 views
in Technique[技术] by (71.8m points)

c# - 'System.Web.WebPages.Html.HtmlHelper' does not contain a definition for 'ActionLink

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:DevelopmentISISIS.TransactionDesk.SPAin
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: D:DevelopmentISISIS.TransactionDesk.SPAweb.config
LOG: Using host configuration file: C:UsersDarrenDocumentsIISExpressconfigaspnet.config
LOG: Using machine configuration file from C:WindowsMicrosoft.NETFrameworkv4.0.30319configmachine.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:DevelopmentISISIS.TransactionDesk.SPARoutingDefaultRouteHandler.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
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...