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><% */ %>
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.
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 .
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 .
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:
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> *@
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With