Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Breakpoints not being hit in asp.net MVC Javascript Event

This seems to be a regular question on SO and I've tried all solutions suggested but no good.

My problem is that in my asp.net mvc website (in VS2012) the breakpoints "ARE" being hit in all my controller code, but they "ARE NOT" being hit in the actual javascript code in the aspx pages. The breakpoints in the javascript is showing the good old "This breakpoint will not be hit. The symbols have not been loaded".

Ive checked all the pdb files and they are all there, and the module window says the symbols are loaded.

Any ideas why the actual markup breakpoints wouldnt be being hit?

Thanks

like image 734
Matt Avatar asked Nov 18 '12 23:11

Matt


2 Answers

Have you tried adding a 'debugger' command in the javascript code? I know this is usually frowned upon though.

Eg:

 $(document).ready(function() {

         ....
         debugger;
         ....

});

You could also try to enable javascript debugging in IE by unchecking both of the Disable script debugging from IE => Options => Advanced.

Reference:

  • http://www.mayanksrivastava.com/2010/02/debugging-java-script-in-visual-studio.html
like image 81
skub Avatar answered Nov 02 '22 20:11

skub


After much battle and research, finding no correct answers, I discovered the problem. Since I am writing in CSHTML files with RAZOR, writing javascript within them seems to be an issue. I had to extract all my javascript out of the files and put them into a .js file. I loaded these files at the top of the cshtml files from a script declaration like so

<script src="~/Scripts/Users/Users.js"></script>
...<body></body>...

Now my breakpoints get hit... This is my answer and it worked. Let me know if it works for you, if so approve this answer so others can figure out this issue.

like image 39
Exzile Avatar answered Nov 02 '22 20:11

Exzile