MVC3 Razor – jQuery – Visual Studio != Intellisense

I wondered where my intellisense had gone for jQuery with MVC3 and Razor. Anyway there is a fix for it:

Add the following to your view (with the jQuery vsdoc version you have:

@if (false) { <script src="~/Scripts/jquery-1.5.0-vsdoc.js" type="text/javascript"></script> }

The if-statement prevents the script tag from being rendered into the html source code.

Grab jQuery 1.5.0 vsdoc from here -> http://damianedwards.com/files/jquery/jquery-1.5-vsdoc.js

ASP.Net -> object does not exist in the current context – really??

Another one of those problems that can stump you for a while. I often make backups of files as I progress and sometimes leave them in the website folder, this was fine with classic ASP but as I have found with ASP.Net can cause all sorts of problems.One issue I was having was trying to reference a component in my aspx page from the codebehind page and seeing the following error when trying to reference a label control:

“Label2 does not exist in the current context”

So I found that the problem was even though I renamed one of my old files it still contained the class that my codebehind was referencing (i.e. the class names were still the same) – and therefore was not seeing the newly added Label control to my new code.Shame the compiler doesn’t realise the duplication and give some indication.

Lesson: Remove any backed up files from the web folder and/or build directory to avoid pain :)

Note:
From a comment made by Chris (below) this can also be caused by a missing files if it was built as a ‘Web Application’ project and you are now trying to build it as a ‘Web Site’ project (e.g. could be missing a designer.cs file).

Either when downloading source from another developer or migrating a web app from one server to another you may find it was actually created as a ‘Web Application’ project in Visual Studio, and if you have created it as a ‘Web Site’ project you may hit problems. The solution to this is to convert the project to a ‘Web Application’ (right click on your project in solution explorer) and then rebuild it.