Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Referring to JavaScript files in Razor views to get JavaScript Intellisense

Visual Studio offers JavaScript Intellisense. It's smart enough to see that you refer to JavaScript files in your master pages (for example jQuery file) and then offers statement completion in any view of the application. However this doesn't seem to work with Razor. Is there a way to get this working with Razor? ASPX view engine offers this trick for example: <% /* %><script src="~/Scripts/jquery-1.4.1-vsdoc.js"></script><% */ %>

like image 997
Konstantin Avatar asked Nov 11 '10 10:11

Konstantin


People also ask

Why is IntelliSense not working in the razor file?

When intellisense stops working in the razor file, there's a good chance that the issue can be fixed in three steps: Close Visual Studio. Delete the solution user options file (<solution-name>.suo) Re-open the solution in Visual Studio.

Why are my JavaScript Intellisense files not working in Visual Studio 2017+?

Please note that starting with v6, the JavaScript intellisense files only work when using Visual Studio 2017+. This is because they are based off of the TypeScript intellisense files and the new language service which uses TypeScript behind the scenes. For more information please see here .

Does typescript IntelliSense work with Visual Studio 2017+?

JavaScript and TypeScript Intellisense. Please note that starting with v6, the JavaScript intellisense files only work when using Visual Studio 2017+. This is because they are based off of the TypeScript intellisense files and the new language service which uses TypeScript behind the scenes. For more information please see here .

Can JavaScript code be used with razor partial views?

When structured properly, JavaScript code can extend the power of JavaScript libraries and custom code to Razor partial views rendered with the unobtrusive Ajax library. The key steps are:


1 Answers

You should be able to do something like this:

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

That way the code will never run when the app runs, but VS won't know about the if (false), so it will parse the <script> tag and allow Intellisense to take it into account. The problem with using Razor comments in Razor files is that VS will recognize them and completely ignore anything inside them. For example, this won't work:

@* <script src="/Scripts/jquery-1.4.1-vsdoc.js" type="text/javascript"></script> *@
like image 82
Eilon Avatar answered Oct 14 '22 11:10

Eilon