Razor Views not seeing System.Web.Mvc.HtmlHelper
Asked Answered
H

22

73

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' does not contain a definition for 'BeginRouteForm' and no extension method 'BeginRouteForm' accepting a first argument of type 'System.Web.WebPages.Html.HtmlHelper' could be found (are you missing a using directive or an assembly reference?)

I also have errors like:

  • "The name 'Viewbag' does not exist in the current context

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:

  • I haven't updated class librarys etc.. in the sln to .net 4.5 yet.
  • The project was created in VS2010, but I am doing the migration in VS2012
  • The project opens and runs OK with VS2012, .Net 4.0, MVC 3

Any pointers appreciated.

Edit: All references and files in web.config upgraded to:

  • System.Web.Mvc, Version=4.0.0.0
  • System.Web.WebPages, Version=2.0.0.0
  • System.Web.Helpers, Version=2.0.0.0
  • System.Web.WebPages.Razor, Version=2.0.0.0

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.

Hermeneutics answered 20/8, 2012 at 16:40 Comment(6)
have you checked your web.configs?Wellwisher
What version of WebPages does your web.config reference?Goad
Hi, did you fix this issue? I am having the same problem. Any help would be great.Unalienable
Sorry, I did... but not in a way I could document. I fiddled with all the configs for a few hours and eventually it started working. I never pinpointed the "magic" fix.Hermeneutics
I'm having a similar problem, but my intellisense errors are when referencing a static class inside my same project. It doesn't find the namespace. Any ideas here?Fluted
please mark him as answar https://mcmap.net/q/272364/-razor-views-not-seeing-system-web-mvc-htmlhelperKanarese
M
94

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, I set to 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. 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

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.

Multifid answered 30/4, 2014 at 13:36 Comment(14)
Matt - I've spent HOURS on this and FINALLY your solution worked. THANK YOU! Unloading, deleting .user and reloading worked for me. What in the heck is the .user file??Analyse
The .user files are Visual Studio's cache of your project settings, such as current windows open, etc. In my experience, if I notice anything wonky, deleting the .user file might help. Also, note the .suo file next to the .sln; it is the same sort of thing, but for the solution file. (In old versions of VS, this file could get corrupted, breaking your intellisense, for instance...)Multifid
Too bad :( this did not work for the same symptoms in VS2015Psychogenesis
@SerjSagan, what version of MVC are you using in VS2015? (MVC6 has changed the names of many methods, removed some, and added others... and removed the web.config, on top of it all.)Multifid
I'm using MVC 5 in my solution.Psychogenesis
Added a note that should do it for VS2015 - note that I have not had this issue myself, so I'm mostly just hoping it fixes it for you! (It IS safe to do what I have suggested, I have confirmed.)Multifid
I agree with @SerjSagan - this does not fix these symptoms in VS2015. The error I am getting is '_Page_Views_Home_Index_cshtml' does not contain a definition for 'ViewBag' within the editor and The type or namespace name 'AspNet' does not exist in the namespace 'Microsoft' in the error list (CS0234). I am using MVC 5 and it all started when I updated to VS2015 from VS2013. If anyone has any assistance it would be greatly appreciated as this is beginning to really annoy me! Grrr!Hoarding
@Hoarding I also still have this issue. MVC 5 was fine on 2013. But, when I upgraded to 2015, these errors popped up. The above 'solution' doesn't help. I'd greatly appreciate it if anyone can help. It's so frustrating!Microparasite
Given the error @Hoarding provides of The type or namespace name 'AspNet' does not exist in the namespace 'Microsoft', it really sounds like similar symptoms as above but completely different issues... If someone opens a new question with visual-studio-2015 asp.net-mvc-5, etc., and links it, I'd gladly upvote.Multifid
I have an existing MVC 4 solution that seems to load fine in VS 2013 but exhibits the issue in VS 2015, much like the problems being reported by @SerjSagan and BWHazel. I just wanted to iterate that I'm not trying to upgrade to MVC 5.. I'm simply wanting to edit my existing MVC 4 in the latest Visual Studio. My solution for now: keep editing my MVC 4 in VS 2013Tranquilizer
If you updated your project from MVC4 to MVC5 you should follow these steps: asp.net/mvc/overview/releases/…Resemble
Other option Close VS2013, Delete .User file, Reopen solution and buildKanarese
After several hours of changes in web.config and stuff my issue was that web.config cannot be linked. It must exist in the project.Quemoy
buggy Visual Studio as always (I'm having VS 2022 installed and still facing this issue!)Gerhart
A
29

I had the same issue when updating to MVC 5 and it was solved by updating the web.config inside the Views folder.

<system.web.webPages.razor>
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.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>

The host -> factoryType was set to version:4.0.0.0 hope this helps anyone.

Apteral answered 2/2, 2014 at 19:31 Comment(1)
Thank you. Literally have tried 20+ different solutions, yours is the first to work. Much appreciated.Hydrotaxis
D
9

I tried all the solutions here but none of them worked for me. Again, my site runs fine but I don't have intellisense and get red wavy lines under a lot of things in my views that Visual Studio does not recognize, one of them being Html.BeginForm(), as well as anything having to do with ViewBag.

I'm working with a new MVC 5 project. After hours of comparing web.config lines, I finally found what fixed it for me.

My web.config in my root had the following line:

<system.web>
  <compilation debug="true" targetFramework="4.5" />

  <!-- ... -->
</system.web>

I compared to a previous project not using MVC 5, and copied over a block I noticed was missing from the new one, which was the following:

<system.web>
  <compilation debug="true" targetFramework="4.5">
    <assemblies>
      <add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
      <add assembly="System.Web.Helpers, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
      <add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
      <add assembly="System.Web.Mvc, Version=5.1.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
      <add assembly="System.Web.WebPages, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    </assemblies>
  </compilation>

  <!-- ... -->
</system.web>

I copied the above block over to my new project's web.config in the root, changing the versions to match the numbers for each assembly found in my project references (right-clicking each reference mentioned and selecting "Properties", "Version" is given at the bottom of the properties window for the selected reference).

After implementing the above, I now have intellisense and don't get any unknown red lines under things like Html.BeginForm, ViewBag.Title, etc.

Declivous answered 13/4, 2014 at 2:28 Comment(3)
Thank for that! Not sure but this might only be necessary in the /Views/Web.Config file but I put it in the root and it did the trick. Cheers.Nils
I revised each reference against actual dll version in properties window and their I found the problem. Thanks mate for pointing me in the right direction.Oligosaccharide
Thanks a lot for this! I had the same issue as you and this fixed it :)Mucilage
M
7

I had run a project clean, and installed or reinstalled everything and was still getting lots of Intellisense errors, even though my site was compiling and running fine. Intellisense finally worked for me when I changed the version numbers in my web.config file in the Views folder. In my case I'm coding a module in Orchard, which runs in an MVC area, but I think this will help anyone using the latest release of MVC. Here is my web.config from the Views folder

    <?xml version="1.0"?>
    <configuration>
      <configSections>
        <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>
      </configSections>

      <system.web.webPages.razor>
        <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.1.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <pages pageBaseType="Orchard.Mvc.ViewEngines.Razor.WebViewPage">
          <namespaces>
            <add namespace="System.Web.Mvc" />
            <add namespace="System.Web.Mvc.Ajax" />
            <add namespace="System.Web.Mvc.Html" />
            <add namespace="System.Web.Routing" />
            <add namespace="System.Linq" />
            <add namespace="System.Collections.Generic" />
          </namespaces>
        </pages>
      </system.web.webPages.razor>

      <system.web>

        <!--
            Enabling request validation in view pages would cause validation to occur
            after the input has already been processed by the controller. By default
            MVC performs request validation before a controller processes the input.
            To change this behavior apply the ValidateInputAttribute to a
            controller or action.
        -->
        <pages
            validateRequest="false"
            pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=5.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"
            pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=5.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"
            userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=5.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
          <controls>
            <add assembly="System.Web.Mvc, Version=5.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" namespace="System.Web.Mvc" tagPrefix="mvc" />
          </controls>
        </pages>
      </system.web>

      <system.webServer>
        <validation validateIntegratedModeConfiguration="false" />

        <handlers>
          <remove name="BlockViewHandler"/>
          <add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />
        </handlers>
      </system.webServer>
    </configuration>
Mcrae answered 5/5, 2014 at 0:49 Comment(2)
For me it was upgrading the <configSections> subitems to version 3.0 from 2.0. Thank you!Gravitative
This is it folks! Pay attention to the version numbers in your Views/Web.config. They must match your referenced assemblies versions.Culmination
G
5

You need to copy Views/Web.config to /Shared. This will tell Razor to use the MVC base type & parser. You can read more here: http://blog.slaks.net/2011/02/dissecting-razor-part-3-razor-and-mvc.html

Goad answered 20/8, 2012 at 16:47 Comment(2)
Thanks, but no joy. I've provided some more information in Edit(2) on the question.Hermeneutics
That eliminated the warning messages, but totally broke the website! We do a lot of MVC development here and I've never seen those files in the /shared folder.Baum
P
3

I was dealing with this issue after upgrading from Visual Studio 2013 to Visual Studio 2015 After trying most of the advice found in this and other similar SO posts, I finally found the problem. The first part of the fix was to update all of my NuGet stuff to the latest version (you might need to do this in VS13 if you are experiencing the Nuget bug) after, I had to, as you may need to, fix the versions listed in the Views Web.config. This includes:

  1. Fix MVC versions and its child libraries to the new version (expand the References then right click onSytem.Web.MVC then Properties to get your version)
  2. Fix the Razor version.

Mine looked like this:

<configuration>
  <configSections>
    <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>
  </configSections>

  <system.web.webPages.razor>
    <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.2.3.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>

  <appSettings>
    <add key="webpages:Enabled" value="false" />
  </appSettings>

  <system.web>
    <httpHandlers>
      <add path="*" verb="*" type="System.Web.HttpNotFoundHandler"/>
    </httpHandlers>
    <pages
      validateRequest="false"
      pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
      pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
      userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
      <controls>
        <add assembly="System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" namespace="System.Web.Mvc" tagPrefix="mvc" />
      </controls>
    </pages>
  </system.web>

  <system.webServer>
    <validation validateIntegratedModeConfiguration="false" />

    <handlers>
      <remove name="BlockViewHandler"/>
      <add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />
    </handlers>
  </system.webServer>
</configuration>
Psychogenesis answered 18/8, 2015 at 4:19 Comment(1)
Tried all... unfortunately no help..! :(Griseldagriseldis
R
3

Update for Visual Studio 2017 Users:

If you have just migrated to Visual Studio 2017 and your project is MVC4, make sure you go back into the VS2017 Installer and check the MVC4 option under the "ASP.NET and web development" section. It is an optional component and not checked by default.

This solved my issue

Refuel answered 12/2, 2018 at 1:54 Comment(1)
That was the fix for me. Thanks.Whorehouse
M
2

In the contracting world I'm often using machines that are using older images. After trying everything above I decided to update my VS 2013 to the most recent version (Update 4). After 90 minutes and a restart the references are working just fine now! Hope this helps!

Methylene answered 28/4, 2015 at 16:44 Comment(1)
Yes, for me also was helpful Update 5 (I installed latest) for Visual Studio 2013.Resemble
O
2

Having tried everything in vain, I discovered that in my case it wasn't working because an incorrect attribute value in Web Project csproj file. When I change ToolsVersion to 14, which matches my current IDE version (i.e. Visual Studio 2015), everything worked like a charm:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition=
  .....
Oligosaccharide answered 10/9, 2015 at 19:15 Comment(0)
C
2

For those of you suffering with this after migrating a project from VS 2013 to VS 2015, I was able to fix this issue by installing the ASP.NET tools update from https://visualstudiogallery.msdn.microsoft.com/c94a02e9-f2e9-4bad-a952-a63a967e3935/file/77371/6/AspNet5.ENU.RC1_Update1.exe?SRC=VSIDE&UPDATE=TRUE.

Celibacy answered 7/1, 2016 at 14:53 Comment(3)
This lead me down the right track. My VS 2105 still needed the Visual Studio Update 1. After updating all was well.Labia
That's interesting, Update 1 didn't fix it for me, but the web tools update did.Celibacy
Worked here but also I had to clear any userdata. Nice Solution.Gasperoni
G
1

Just to expand on Matt DeKrey's answer, just deleting the csproj.user file (without needing to recreate solutions) was able to fix the problem for me.

The only side effect I had was I needed to reset the Start Action back to using a specific page.

Gesticulatory answered 3/11, 2014 at 4:22 Comment(0)
A
1

I used the following article on MSDN to solve this issue (in this case from MVC 4 to MVC 5)

https://learn.microsoft.com/en-us/aspnet/mvc/overview/releases/how-to-upgrade-an-aspnet-mvc-4-and-web-api-project-to-aspnet-mvc-5-and-web-api-2

Main extracts from the article are:

Main Web.config (Not the one in the Views folder)

In the runtime block update System.Web.Mvc to 5.0.0.0 ,System.Web.Helpers to 3.0.0.0 and System.Web.WebPages to 3.0.0.0

<dependentAssembly>
  <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
  <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>

<dependentAssembly>
  <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
  <bindingRedirect oldVersion="1.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
</dependentAssembly>

<dependentAssembly>
  <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
  <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>

Then look for the appsettings block and update the webpages:Version value to 3.0.0.0

<appSettings>
    <add key="webpages:Version" value="3.0.0.0" />
</appSettings>

Views Web.config

Update the host factoryType block to System.Web.Mvc to 5.0.0.0

<system.web.webPages.razor>
   <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
   <pages pageBaseType="System.Web.Mvc.WebViewPage">
      <namespaces>
         <add namespace="System.Web.Mvc" />
      </namespaces>
   </pages>
</system.web.webPages.razor>

Then under the pages block update any references to System.Web.Mvc to 5.0.0.0

    <pages
      validateRequest="false"
      pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
      pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
      userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
    <controls>
      <add assembly="System.Web.Mvc, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" namespace="System.Web.Mvc" tagPrefix="mvc" />
    </controls>
  </pages>

And finally under the configuration block update the System.Web references to 3.0.0.0

<configuration>
  <configSections>
    <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>
  </configSections>
Archie answered 14/6, 2017 at 14:31 Comment(0)
I
1

Recently got the same problem and this is how i fixed it: On Visual Studio with your project in question open, Goto:

  1. Tools -> NuGet Package Manager -> Manage NuGet Packages for Solution.
  2. On the open window, select Updates. then Click Update All.

It will load whats missing in your project and all should be back on track.

Isocline answered 12/10, 2017 at 10:27 Comment(0)
S
0

Just started looking into the issue myself and this is what it look like in my case. If you have the correct values in your web config then Its just a bug in MVC4. http://connect.microsoft.com/VisualStudio/feedback/details/727729/viewbag-not-recognized-in-asp-net-mvc-4-project

Sneeze answered 30/7, 2013 at 21:37 Comment(0)
S
0
*<system.web>
<compilation debug="true" targetFramework="4.5">
    <assemblies>
        <add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.Helpers, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.Mvc, Version=5.1.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.WebPages, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    </assemblies>
</compilation>*

This configuration is missing, add it and set appropriate version of assemblies

Swam answered 10/8, 2015 at 18:24 Comment(0)
U
0

As a variation on a theme, I could have sworn up and down that my Views\Web.config was correct:

<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />

But I in fact needed to reference Version=4.0.0.1, not Version=4.0.0.0 because of that security update that got pushed out a while back.

Upsweep answered 2/10, 2015 at 20:23 Comment(0)
W
0

As for me, it was a stupid deployment mistake: Web projects can have more than one web.config. It was working on the developer's machine and not in production, but we were not realising that the deployment script only grabbed the Web.config file at the root, and it didn't copy the Web.config file in the Views folder.

Warren answered 30/5, 2016 at 12:8 Comment(0)
S
0

I've encountered this specific issue as well; no (or incorrect) intellisense showing when trying to use razor tags. My specific issue was VS2015 complaining that Html.BeginForm was not existing in the current context.

I've got areas set up in my MVC project, and managed to narrow down the cause of my error to the web.config file for a specific area, rather than the global web.config.

It turns out that the cause of this issue for me was that I'd added a SQL connectionString into the web.config for the area that was not working, this (I am assuming) caused a parsing error, however the project compiled up correctly.

Moving the connectionString to the global web.config has rectified the issue. Hopefully this may be of some use to others.

Saphra answered 7/6, 2016 at 12:3 Comment(0)
S
0

My situation only occurred after I created a custom class called BaseViewPage that overrode the WebViewPage class. I initially added the following to my Main Web.confg file:

<pages pageBaseType="ZooResourceLibrary.Web.Support.BaseViewPage">

And the same to the View folders web.config file:

<pages pageBaseType="ZooResourceLibrary.Web.Support.BaseViewPage">

I tried many of the other answers and none did the trick while still allowing me to keep my BaseViewPage class. The way I fixed it was to remove the pageBaseType attribute from the Main Web.config file only. Keep it in the View web.config.

Spontoon answered 18/1, 2017 at 16:58 Comment(0)
C
0

I came across several answers in SO and at the end I realized that my error was that I had misspelled "Html.TextBoxFor." In my case what I wrote was "Html.TextboxFor." I did not uppercase the B in TextBoxFor. Fixed that and voilà. Problem solved. I hope this helps someone.

Crenel answered 23/2, 2017 at 21:30 Comment(0)
P
0

Right, I've been trying to fix this issue for sometime. I've used all the solutions in the various Stack Overflow topics regarding this and none seemed to be working.

I have just fixed the issue this morning. After you gave fixed the web.config for both the project and the views, making sure all the .dll versions are matching with what you have in the references folder. You will need to unload the project, edit the .csproj, and then update all the .dll versions in that file.

System.Web.Helpers
System.Web.Mvc
System.Web.WebPages

Hope this helps, as I have finally fixed this issue! No more red squiggly lines.

This has also fixed the context menu issue I was having where, I wasn't getting the option to add a controller, view etc.

Pacificas answered 18/11, 2017 at 10:17 Comment(0)
P
-1

For me the solution was to change the following:

  <pages
        validateRequest="false"
        pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
        pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
        userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
      <controls>
        <add assembly="System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" namespace="System.Web.Mvc" tagPrefix="mvc" />
      </controls>
    </pages>
Preoccupancy answered 22/2, 2016 at 9:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.