Breakpoints not being hit in asp.net MVC Javascript Event

11,379

Solution 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:

Solution 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.

Solution 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).

Share:
11,379
Matt
Author by

Matt

By Day: R&amp;D Manager at a software company that develops Enterprise software for companies throughout the world. By Night: A devoted husband and father of 2. Enthusiast of lifting heavy weights at the gym and enjoying company of friends.

Updated on July 29, 2022

Comments

  • Matt
    Matt almost 2 years

    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

  • Tedd Hansen
    Tedd Hansen almost 10 years
    This worked to get TypeScript breakpoints to work in ASP.Net MVC solution under Visual Studio 2013. Thanks. :)
  • Rhys Bevilaqua
    Rhys Bevilaqua almost 10 years
    This shouldn't actually be necessary, I've had it working all day and suddenly its not happening anymore. That said, it's probably good practice anyway just to allow caching and minification of the .js file
  • Exzile
    Exzile almost 10 years
    It shouldn't be necessary, but like you said, it started to happened to me one day and this was the solution. It does enforce you to break you coding into separate files, which is a good practice.
  • FredyWenger
    FredyWenger over 8 years
    This is true especially also for VS2015 and ASP.NET MVC-6 RC. Default set Browser is edge, where the debugger don't stop. As soon as I have changed the default Browser in VS2015 to IE, debugger stops now AND ALSO SHOW ERROR MESSAGES. So thanks for this hint. Note: I have my Java code directly in the .cshml-file yet.
  • eaglei22
    eaglei22 about 7 years
    I can hit them in Firefox, I just have issues when using them inside asp.net mvc 4 partial views...
  • BrainSlugs83
    BrainSlugs83 about 7 years
    This does not appear to have any effect.
  • BrainSlugs83
    BrainSlugs83 about 7 years
    Same issue. -- The breakpoint in the JS file will also not be hit it says.
  • Exzile
    Exzile about 7 years
    @BrainSlugs83 it should. You nee to make sure the js is a file in its self. (.js). If its not loading the breakpoints its because it's cached. CTRL+F5 it.
  • John VanZwieten
    John VanZwieten almost 6 years
    This is no longer true of VS2017 as of: blogs.msdn.microsoft.com/webdev/2016/11/21/…
  • Mick
    Mick over 2 years
    This worked for me. Frowned upon or not I've been struggling to get the breakpoints to work in a VS2019 MVC5 .js file which is loaded from a script declaration in a partial view, and this solution just worked. Thanks!