0

I'm trying to develop an application in ASP.Net MVC5. I have written some JQuery functions in my Razor page. I want to take those JQuery functions to an external JS file and include it to the .cshtml page. this is how I referred the Js file in .cshtml file

<script src="~/Js/Driver.js"></script>

If I write alert("External JS file loaded successfully"); in my Driver.js file, the message box is popped up successfully. But if I write this function

$("#btnCreate").click(function () {
alert("Create button clicked");});

in that file, it shows below error in console.

enter image description here

how to fix this?

JayNaz
  • 343
  • 1
  • 5
  • 24
  • You need to include `jquery-{version}.js` in your view (or layout) –  Jun 20 '16 at 06:03
  • I have included it in my _layout.cshtml file. internal JQuery functions are working successfully. My problem occurs when I migrate JQuery functions to an external js file. – JayNaz Jun 20 '16 at 06:06
  • Have you referenced Jquery? $ is a Jquery syntax – It's a trap Jun 20 '16 at 06:10
  • @RachitGupta I have referred the JQuery in the layout page. But not in my view page (cshtml) or external js file. – JayNaz Jun 20 '16 at 06:15

0 Answers0