5

I have started a new asp.net core 6 (mvc) project on Visual Studio 2022 and added jquery to wwwroot/jquery folder. when typing jquery functions intellisense isn't working. I've tried adding a reference path like on old visual studio versions and it didn't work.

https://i.stack.imgur.com/2WNN0.png

then tried adding a jsconfig.json file like recommended on some posts that I've found but that also didn't work probably since I'm working offline and it supposed to fetch something from the internet. can anyone help?

Vadim P.
  • 51
  • 1
  • 4
  • There is two way to include dependency before using, first one load js in entry file/current loaded file and second one is bit complex which is load the js dependency before using based on the condition. – Abhishek Jan 06 '22 at 11:12

3 Answers3

5

This fixed the problem for me on Visual Studio 2022:

Put this line on the very top of your .js file (of course with the correct jquery path)

///<reference path="Scripts/jquery-3.5.0.js" />
Ahmed Suror
  • 439
  • 6
  • 17
  • 1
    Adding this reference did indeed work, however when I'm editing script code in a Razor Page view section, the intellisense only appears when I have my site.js containing the reference open in the editor alongside the .cshtml view I'm editing. Odd, but whatever works. – retiredcoder Jul 31 '23 at 12:18
  • @retiredcoder Yes there are some weird issues, especially on *VS 2022*, however, it's a small workaround! Also, there are some issues (sometimes) in bootstrap intellisense! – Ahmed Suror Aug 03 '23 at 02:20
1

I had a very similar problem. In a project created by a coworker, jQuery Intellisense was not working for me. After weeks of server-side development in the project, I started a front-end development task and found that I had no jQuery Intellisense. All I had to do to revive jQuery Intellisense was to close the solution, delete the .vs folder (hidden) for the solution, then reopen the solution.

Note: Doing this erases your personal "settings" for the solution; for example, which files you had open (tabs), your project-tab color settings, etc.

See step 2 here for the source of this resolution: https://stackoverflow.com/a/61475198/1766253

Lee Cichanowicz
  • 101
  • 1
  • 6
  • hi, didn't work for me. had to switch to TypeScript to make the intellisense work – Vadim P. Jun 23 '22 at 12:05
  • Erasing personal settings did not resolve for me either. – tnk479 Sep 08 '22 at 01:37
  • @VadimP. What do you mean by `switch to TypeScript` and how? – Ahmed Suror Nov 07 '22 at 20:51
  • 1
    @AhmedSuror you have to add a tsconfig.json file to the project root and add there all the references to the typescript libraries you are going to use with javascript (for javascript intellisense). the new intellisense engine uses ts files for js intellisense. when you are working online it just downloads them in the background from the "DefinitlyTyped" library at https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types – Vadim P. Nov 08 '22 at 21:43
0

i had the same problem. the solution was to put this line of code in my csproj file :

<ItemGroup>
    <Content Include="wwwroot\lib\jquery\dist\jquery.min.js"/>
</ItemGroup>