0

On my views, I have a red squiggle under '@model' and 'ViewBag' and when I hover over them it says "The name 'model' does not exist in the current context.

I googled this issue and found a lot of answers pertaining to mvc3, but I tried the suggestions and have had no success. I created a new mvc4 application and copied the web.config from the views folder into my own, but that caused a build error. However, my solution builds successfully, and the site runs locally. I'm not sure if there's even a problem since the site is building, but I want to get rid of that red squiggle.

In the web config, this is my Mvc reference:

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

and here is the web.config that I have in the Views folder:

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

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

<system.web>
  <httpHandlers>
    <add path="*" verb="*" type="System.Web.HttpNotFoundHandler"/>
  </httpHandlers>
  <pages
      validateRequest="false"
      pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
      pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
      userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
    <controls>
      <add assembly="System.Web.Mvc, Version=4.0.0.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>

I have version 4.0.40804.0 of System.Web.Mvc installed on my computer. I assume there's something wrong with the versions referenced in the Views config, but I don't know what the correct values should be. I tried creating a new mvc4 solution as suggested in another post and copying the Views config, but that didn't work.

Erica Stockwell-Alpert
  • 4,624
  • 10
  • 63
  • 130
  • Compare csproj files (yours and clean MVC4/5 project) - you'll likely find some project type id mismatch... Side note: please update post to confirm that you are using `@Model` and not `@model`. – Alexei Levenkov May 13 '15 at 14:42
  • I was not using @Model. I changed it and that fixed that issue, but ViewBag still has a squiggle. – Erica Stockwell-Alpert May 13 '15 at 15:04
  • Check all your versions. For example you have `` (4.0.0.0 is not the same as 4.0.0.1) –  May 13 '15 at 22:34
  • did u check this link http://stackoverflow.com/questions/6389055/the-name-model-does-not-exist-in-current-context-in-mvc3?rq=1 – Razack May 14 '15 at 10:02

1 Answers1

0

I had same issues when I migrated MVC3 app to MVC 4, I tried all the various suggestions I could find on the web. Finally I decided to stop finding a work-around solution. I simply created a new MVC app and added new controllers and views (NOT copied them). And then copied over the code.

Most important part is I think leaving new project's Web.Configs intact, and copying which were specific bits needed instead of overwriting whole file.

Jayvin
  • 56
  • 3
  • Unfortunately I don't think I can do this, as this is a huge project and it's source controlled in Github – Erica Stockwell-Alpert May 13 '15 at 15:03
  • ok in that case you've to do it other way around. create a new project and add a controller and a couple of views similar to those in your actual project. Then do a diff on web.config files and copy over tags from New project's web.config which are missing in old project's webconfig file. – Jayvin May 14 '15 at 15:37