7

I am coding a PlugIn to NopCommerce 3.2, and in the views I get the error mentioned above, but also for 'Layout' and 'Html'. I have copied the same Web.Config that works in another plugin. I have also added the same references as used in the working Plugin. When compiling the plugin works, but I don't have any intellisense and can't trust that VisualStudio marks errors correctly. I am using VS2013 Professional Update 1.

Here is the Web.Config file:

<?xml version="1.0" encoding="utf-8"?>

<!-- We use this file to make razor intellisense work in the class library -->




<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>
  <appSettings>
    <add key="webpages:Version" value="3.0.0.0" />
    <add key="webpages:Enabled" value="false" />
    <add key="PreserveLoginUrl" value="true" />
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
  </appSettings>
  <system.web>
    <compilation targetFramework="4.5" />
    <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>
      <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.Routing" />
        <add namespace="System.Web.WebPages" />
      </namespaces>
    </pages>
  </system.web>
  <system.web.webPages.razor>
    <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <pages pageBaseType="Nop.Web.Framework.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" />
      </namespaces>
    </pages>
  </system.web.webPages.razor>
</configuration>

EDIT: Sorry if you find this question not researched, but I assure you I have spent hours to try to find the solution (including those questions I have found here in stackoverflow that are similar and pointing out web.config as the problem which is the reason I have included that file in my question) but can't find it.

hjd
  • 131
  • 1
  • 2
  • 8
  • You you did not copy the same total project? – Ramesh Rajendran Feb 27 '14 at 08:48
  • I have used parts from other projects (just like with other plugins I recently created), but not copied the entire project. You mean the solution would be to copy the working project and switch the code inside? Problem is I have about 30 projects that is not working anymore and only a few working. I don't know why they suddenly stopped working, but probably due to updates in nuget packages. Don't understand why some projects work though... – hjd Feb 27 '14 at 20:32
  • Possible duplicate of [Razor View throwing "The name 'model' does not exist in the current context"](http://stackoverflow.com/questions/19696963/razor-view-throwing-the-name-model-does-not-exist-in-the-current-context) – Michael Freidgeim Apr 13 '16 at 07:01

10 Answers10

5

This error was probably caused by Resharper. We are a team of three developers using GIT. One of us installed Resharper, and this probably caused the error for the other two of us. When we installed Resharper trial it suddenly worked again. Unfortunately it isn't working when uninstalling Resharper again...

hjd
  • 131
  • 1
  • 2
  • 8
  • I have exactly this problem. It compiles and runs fine. But intellisense does not work and gives this message that the name Model does not exist. Resharper broke my vs and the trial is over so I uninstalled it and am left with broken intellisense. – JP Hellemons Nov 11 '15 at 10:39
  • 1
    I can confirm that the inability to detect @ model is due to my ReSharper Ultimate extension. I disabled ReSharper, exited VS 2017, opened VS 2017, cleaned, built the project, re-enabled ReSharper. The intellisense red lines for @ model disappeared. – Jimmy Shaw Oct 06 '17 at 16:04
2

Try to add this section in system.web. (Make sure the versions i added are indeed the ones you are using)

<compilation targetFramework="4.5">
  <assemblies>
    <add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <add assembly="System.Web.Helpers, Version=2.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.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <add assembly="System.Web.WebPages, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
  </assemblies>
</compilation>

Close the .cshtml view files. Rebuild the project. And open them again.

Marius Stănescu
  • 3,603
  • 2
  • 35
  • 49
  • Tried it, but it still doesn't work. How do I check which version to use? In Nuget it says that System.Web.WebPages is version 3.1.1, but when I use it in blank templates I always get version 3.0.0.0. – hjd Mar 05 '14 at 08:04
2

Un-installing the project MVC Nuget Package and Reinstalling it fixed it for me. Mine got botched when I changed the .net version of the project.

netslaves
  • 60
  • 6
1

Ensure that the namespace that you have defined on view is matching with your model's namespace.

mariann
  • 456
  • 2
  • 7
  • The namespace definition in the view (using ...) is matching the one in the model. – hjd Feb 28 '14 at 11:07
1

If you change your project properties to target 4.5.1,

targetFramework in LOTS of other places will still say 45

You can find targetFramework 3-4 times in your root web.config and in all kinds of packages.config.

I had same problem, change Project to target 4.5 and it cleared up.

Best to not target 4.5.1

user965445
  • 115
  • 1
  • 10
1

I had the same problem. The solution was to uninstall the project MVC Nuget Package and Reinstall it.

http://mhammadchehab.com/wordpress/2013/12/enabling-intellisense-for-razor-in-class-library-mvc-5-razor-3-0/

David
  • 1,560
  • 2
  • 16
  • 32
1

Change the Project Output path to /bin for All Configurations in the Project Properties. This is odd, but it seems when the VS Project Output is pushed to /bin/Debug or /bin/Release the intellisense is completely busted.

project properties

SliverNinja - MSFT
  • 31,051
  • 11
  • 110
  • 173
1

I experienced the same error in my MVC 5 project. My case was that the Web.config in Views folder was not published somehow. Adding it back solved the issue.

Stephen Zeng
  • 2,748
  • 21
  • 18
1

I my case, I had to reset the Visual Studio Component Cache by closing Visual Studio and deleting this folder:

C:\Users\[username]\AppData\Local\Microsoft\VisualStudio\14.0\ComponentModelCache

Vojta Jemelka
  • 136
  • 1
  • 6
0

I had the same error and just changed

<pages pageBaseType="Nop.Web.Framework.ViewEngines.Razor.WebViewPage">

to

<pages pageBaseType="System.Web.Mvc.WebViewPage">

I am just trying to get cshtml intellisense in a console application so it worked for me to go back to the standard base webviewpage.

Echilon
  • 10,064
  • 33
  • 131
  • 217
StewartArmbrecht
  • 1,221
  • 1
  • 10
  • 20