Breakpoints not being hit in asp.net MVC Javascrip

2020-06-04 05:25发布

问题:

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

回答1:

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


回答2:

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.



回答3:

Breakpoints in Javascript are hit ONLY when debugging using Internet Explorer, the other browsers donot work. (I tried Chrome + Firefox anyhow, not sure about the others).