Problems after Razor update in VS2012 - asp.net-mvc

After installing some updates in VS Package Manager (including Razor update), my Intellisense and code Highlighting is malfunctioning. Even the basic things like model, ViewBag, Html.BeginForm() are all being highlighted red; hovering over them shows either 'doesnt exist in current context' or 'so and so doesnt have definition for BeginForm'...Ironically the code compiles perfectly as before and runs fine...
What gives?

Razor 3 uses a new engine, which VS2012 doesn't have. You can add support by installing the new ASP.NET and Web Tools 2013.1 for Visual Studio 2012

Related

Unable to create MVC View using scaffolding in Visual Studio 2013 Ultimate Update 5

I recently applied Update 5 to Visual Studio 2013 (Ultimate Edition) running on Windows 8.1. After the update, any time I try to create a Razor View (*.cshtml) file in my MVC application using scaffolding, I get the following error:
There was an error running the selected code generator:
The Templates\PackageVersion5.1.3.xml file is missing from the
installed template folder
From the error, it is clear that some file (PackageVersion5.1.3.xml) is missing but I'm not sure how to fix it. I even repaired Visual Studio but to no avail.
As yoo probably know during scaffolding your view is generated base on this missing xml file. I don't know why your file is not there but you can copy it from one of your colleagues computer or reinstall visual studio.
Maybe you have change something i VS options?
I avoid the scaffolding options in Visual Studio.
Why? In my experience, the standard MVC pattern where everything separated by type will always led to a difficult to manage and test solution.
Instead, I now prefer to organise MVC projects by feature (http://timgthomas.com/2013/10/feature-folders-in-asp-net-mvc/).

Upgrading to Visual Studio 2015 renders intellisense broken for project

I've been through a lot of similar issues, but could not find anything that worked for me.
I'm upgrading my IDE from the VisualStudio for Web (v10) to Visual Studio 2015 (v14, I guess) Community Edition.
The main project that I'm trying to use on the new IDE is a MVC 5 (5.2.3), with EF 6.1 (6.1.3) and a bunch of other stuff.
Problem is: When opening the project on the new IDE, everything looks fine (it even compiles and work). I got the MVC context menu working on the project explorer (showing the "Add Controller..." and "Add View..." when appropriate). Only (really annoying) thing is the Razor Intellisense.
When I do open a View file (.cshtml) I receive warnings on several helpers, some of the "using" are greyed out (even though they're supposed to be needed) and the #model myModel is shown like everything after the #model directive is not razor (it's treated like HTML by the intellisense coloring).
What I've already found and tried:
I've already tried to clear the UserData from the vs (devenv /ResetUserData)
I've already tried to run the VS2015 in safe mode
I've already tried to run VS2015 as Administrator
I've already tried to set the Project's target framework to 4.5.1 (used to be 4.5)
I've already tried to open the project on Visual Studio Community 2013 saving it there before trying to use it on VS2015.
When creating another MVC project from the VS2015, everything works fine.
Here's an example of the annoying issue:
Ok, finally got it.
Posting what I found out believing it may help someone else:
What seems to cause the problem mentioned is the fact that the project was created on an old MVC version (with older Razor, EF, etc).
As stated in this answer: Visual Studio 2015 Razor View MVC Types not recognized, VS2015 tools may not work for older MVCs.
The solution is to update all your packages to [at least] the minor versions accepted on newer MVC (5?). To do so you can use the list in this 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.
Once everything is up-to-date, open the web.config files located on root of your application and on the Views folder. In there, you will probably find some references to the older versions of MVC and Razor. Update those versions values (all of them) to match the updated versions of your packages (you may create a new empty MVC project on the new Visual Studio and check for those values as a hint of what they should be).
This step is the catch! Since, even if you update you project's packages, some web.config references may still mention the original versions.
Clean the solution (Build > Clean Solution) and close the project. Reopen and compile it. Now [hopefully] everything should be working fine.
[Edit]
One more thing: If your project was also updated from Framework 4.5 to 4.5.1 during this IDE transition, you should also install a NuGet package called "Microsoft.CodeDom.Providers.DotNetCompilerPlatform" (as stated in https://support.microsoft.com/en-us/kb/3025133).

VS2015 ASP.NET MVC the name 'model' does not exist in the current context

I was working on an ASP.NET MVC 4 in VS2013 and everything was fine, then I've uninstalled 2013 and installed 2015, I was able to open the project, build it and even run, everything works fine (run/debug). The problem is that all my views are covered in errors:
the name 'model\Scripts\Url...' does not exist in the current context
In addition, the .Where method of a list in the model shows an error as well as all the #Html helpers. I want to emphasize that the project still works w\o any problems so the issue is UI or package related. I tried to force uninstall\upgrade Microsoft.AspNet.MVC but the package manager console throws an error and rolls back the attempt. I can provide any necessary info if it helps, thank you in advance.
The newly released VS2015 IDE seems to no longer support MVC3/MVC4 projects, while it only supports the MVC5:
Unable to find MVC3 , MVC4, MVC5 projects (or) No information about supported MVC Framework versions
If there are strict requirements to convert any existing MVC3/4 solution to MVC5 (for VS 2015), you can proceed with the steps listed in the
How to Upgrade an ASP.NET MVC 4 and Web API Project to ASP.NET MVC 5 and Web API 2 guide.
Update 2016-05-03
It seems that after installing the VS 2015 SP2 update, it behaves much better. If you have a chance, I suggest that you upgrade your IDE and check if the issue goes away.

Getting MVC 3 razor view intellisense to work with Visual Studio 2013

I am facing the same issue sited here. Basically, the MVC3 razor view (cshtml) intellisense does not work with VS 2013. The reason sited on that thread is that MVC3 is not supported in VS 2013. Now I have a third party library (dll) that I cannot upgrade to MVC4 or MVC5 without incurring additional cost. I am doubtful whether the MVC3 version of that library that I am currently using will correctly work with MVC4 if I upgrade my VS 2013 project to MVC4 for intellisense.
Coming back to my question, is there any way to get the VS 2013 razor view intellisense working for MVC3 . Other than intellisense, there is no issue and the project compiles and runs without any problems.
EDIT
As can be seen from the snapshot below, intellisense works for some statements like #Html.Label(..) but not for #Html.DisplayFor(..), Html.TextAreaFor(..) and others.
Add these two lines inside each view:
#inherits System.Web.Mvc.WebViewPage<dynamic>
#using System.Web.Mvc.Html
Instead of dynamic put your Model's type name.

ASP.NET MVC 3 Razor Intellisense

Downloaded and installed ASP.NET MVC 3 (final version) and still I do not have intellisense in Razor views? What is wrong?
Install the ReSharper 5.1.2 update and then ASP.NET MVC 3 Razor Intellisense will work again.
ReSharper 5.1.2 doesn’t interfere with Visual Studio IntelliSense in ASP.NET MVC 3 Razor syntax. Earlier ReSharper 5.x builds had certain issues with Razor IntelliSense that are addressed in 5.1.2. Specifically, ReSharper 5.1.2 doesn’t prevent Visual Studio from automatically providing its own IntelliSense in .cshtml and .vbhtml web pages anymore: both code completion and Parameter Info work as expected.
http://blogs.jetbrains.com/dotnet/2011/01/resharper-512-is-released/
If you have R# installed, change the settings to use VS Intellisense instead of R#'s. R# does not have that capability for Razor yet. If you still want to use it you could try hitting the space bar after the period
Are you up to date with service packs. Off the top of my head I think you need Visual Studio Service Pack 1 beta for it to work

Resources