16

I am working on a MVC project in Visual Studio 2015 (originally created in VS 2013)

It all builds correctly, but while coding, the views show alot of errors.

@{
 ViewBag.Title = "Index";
Layout = "~/Views/Shared/_Layout.cshtml";

string quoteType = "Fee Estimate";
if (Model.Quote.QuoteType == "QuoteType")
{
}
}

In this code that is on the top of one of my views, the Viewbag, Layout & Model is all underlined showing an error.

The errors are:

Error CS0103 The name 'Model' does not exist in the current context Quilgroup C:\,,,\Index.cshtml 268

Error CS0234 The type or namespace name 'Mvc' does not exist in the namespace 'Microsoft.AspNet' (are you missing an assembly reference?) Quilgroup C:...\Index.cshtml 1

I think it is something wrong with the dev enviornment, because it still compiles and runs correctly.

Michael
  • 8,229
  • 20
  • 61
  • 113
  • 2
    Probably the result of version mis-matches in your `web.config.cs` file. Look at all the version numbers and the `` elements to see they all match up. –  Aug 17 '15 at 23:39
  • 1
    To ask the dumb question: have you walked through the steps [shown on the ASP.NET website](http://www.asp.net/mvc/overview/releases/how-to-upgrade-an-aspnet-mvc-4-and-web-api-project-to-aspnet-mvc-5-and-web-api-2) for upgrading an MVC4 project to MVC5? I realize that it's referring to Visual Studio 2013, but the changes may still be relevant. – Tieson T. Aug 22 '15 at 04:02
  • @michael Clean your solution and then set the property of those files to Copy Local = True. – Krsna Kishore Aug 22 '15 at 05:12
  • I tried to clean solution and set dlls to local copy, and it did not help – Michael Aug 25 '15 at 23:24

4 Answers4

19

Delete %localappdata%\Microsoft\VisualStudio\{version}\ComponentModelCache folder then restart Visual Studio.

I had the same problem and this solved it.

Source: After installing AspNet5RC1, can no longer open cshtml files in any previous / new MVC project

Community
  • 1
  • 1
L.Trabacchin
  • 1,538
  • 1
  • 17
  • 34
  • Thanks very much. I had this problem after loading a few extensions into visual studio 2015 community edition and my system hanging. Tried a lot of things (web.config edits, devenv /resetuserdata etc) based off various questions and answers here but this one worked. – andyb Sep 11 '16 at 14:27
  • In my case I had to update visual studio to last version then accomplished what you mentioned and it worked. – Muhammad Musavi Nov 26 '18 at 05:41
0

This is a tooling problem. VS 2015 contains MVC tooling only for MVC version 5.x and above. You need to upgrade ASP.NET MVC to version 5+.

I other words your MVC 4.x app will still be compiled and run correctly but the development experience and editing in VS will be less optimal (a lot of error like underlines, go to view won't work, etc.)

Liviu Mandras
  • 6,540
  • 2
  • 41
  • 65
  • 1
    unfortunately my site is already updated to MVC 5. I followed this link http://world.episerver.com/documentation/Items/Upgrading/EPiServer-CMS/8/upgrading-from-mvc-4-to-5/ it did not help :( – Michael Aug 25 '15 at 23:23
0

May be, You are missing the reference inclusion part and Model has been called instead of model.

*<!--add the refrence, you are missing the reference. this should remove those errors-->*
@model ManageQuote.Models.Quote
@{
 ViewBag.Title = "Index";
Layout = "~/Views/Shared/_Layout.cshtml";

string quoteType = "Fee Estimate";
*<!-- use model instead of Model,I think its what you should be calling here, it would be easy if model classes were known -->*
if (model.Quote.QuoteType == "QuoteType"){
   }
}
aimme
  • 6,385
  • 7
  • 48
  • 65
0

Open your project folder search for *.suo files delete all these files

open .sln file in notepad or notepad++ then check for the assembly paths, are they mapped correctly? if not then map it correctly.

Then clear all your temporary files.

Clean your code. Rebuild. This will solve your problem.

Amar Gadekar
  • 387
  • 4
  • 11