如何使用Javascript调试来使用我的ASP.NET MVC应用程序?

时间:2022-05-16 03:30:55

I can't seem to get Javascript debugging working for my ASP.NET MVC application even though I can for a traditional ASP.NET WebForm app.

我似乎无法使用Javascript调试为我的ASP.NET MVC应用程序工作,即使我可以使用传统的ASP.NET WebForm应用程序。

I have followed the steps for unchecking the 'Disable Script Debugging' boxes for both IE and other.

我已经按照步骤取消选中IE和其他的“禁用脚本调试”框。

when I add a simple function to display an alert in both the site.master and any content view the breakpoint will not fire.

当我添加一个简单的函数来在site.master和任何内容视图中显示警报时,断点不会触发。

Have i missed something obvious or do I need to use an outside tool for debugging like FireBug?

我错过了一些明显的东西,还是需要使用外部工具进行调试,如FireBug?

By the way, I'm using Visual Studio Web Developer Express 2008.

顺便说一句,我正在使用Visual Studio Web Developer Express 2008。

thx

5 个解决方案

#1


6  

function test()
{
  debugger;
  alert("hi");
}

I don't know if it will work with express, but when IE hits the "debugger" instruction, it asks me if I want to debug, and with wich tool. Visual studio is present in the list of options presented to me.

我不知道它是否适用于express,但当IE点击“调试器”指令时,它会询问我是否要调试,并使用wich工具。 Visual Studio出现在提供给我的选项列表中。

I don't know if express will be present for you though.

我不知道快递是否会出现在你面前。

"debugger" also works with firebug.

“调试器”也适用于firebug。

#2


5  

I just had this problem today as well. The debugger doesn't know where you script files are if you include them in the mvc view.

我今天也遇到了这个问题。如果将脚本文件包含在mvc视图中,则调试器不知道脚本文件的位置。

Put them in an external .js file (say default.js) in the scripts folder, add a script tag in the site.master and then you will hit your breakpoints.

将它们放在脚本文件夹中的外部.js文件(例如default.js)中,在site.master中添加脚本标记,然后您将点击断点。

#3


2  

VS JS debugging can work, but... Honestly, get Firebug. It's free, and does much, much more than the VS debugger.

VS JS调试可以工作,但是......老实说,得到Firebug。它是免费的,并且比VS调试器做得更多。

#4


1  

Here's my workaround for debugging javascript in MVC. VS2008 doesn't pick up on break points for javascript in an aspx page, but it will for a separate .js file. I create a debugJscript.js file when I'm working on a page. I create a reference to that debug page from my aspx page. I can step through javascript that way and then push the javascript code back to the aspx page when I'm happy with it.

这是我在MVC中调试javascript的解决方法。 VS2008没有在aspx页面中获取javascript的断点,但是它将用于单独的.js文件。我在页面上工作时创建了一个debugJscript.js文件。我从我的aspx页面创建了对该调试页面的引用。我可以通过这种方式逐步执行javascript,然后在我对它满意时将javascript代码推回到aspx页面。

You can avoid caching problems, too, on that external .js file if you refer to your file like so:

如果您像这样引用文件,也可以避免在外部.js文件上缓存问题:

    <script type="text/javascript" src="../../Scripts/DebugJScript.js?<%=DateTime.Now %>" ></script>    

#5


-1  

I don't use VS.Net Express, but in VS.Net Standard you can go to the Debug menu in your solution and choose "Attach to process". You will then get to choose the debug type: Native, Managed, or Script. Select Script, then select your process from the list. A list of scripts will now come up in your IDE. Click on script one you want to debug, throw in a breakpoint or two, and you should be ready to go.

我不使用VS.Net Express,但在VS.Net Standard中,您可以转到解决方案中的Debug菜单,然后选择“Attach to process”。然后,您将选择调试类型:Native,Managed或Script。选择脚本,然后从列表中选择您的流程。现在,IDE中将出现一个脚本列表。单击要调试的脚本,输入一两个断点,然后就可以开始了。

If MS has nerfed the Express version so that you can't attach to a process, then I guess you're stuck and will need the $$$ upgrade (which wouldn't entirely surprise me). Hey, what do you want for free? :)

如果MS已经对Express版本进行了监视,那么你就无法连接到一个进程,那么我猜你会被卡住并需要进行$$$升级(这并不会让我感到惊讶)。嘿,你想要什么免费的? :)

#1


6  

function test()
{
  debugger;
  alert("hi");
}

I don't know if it will work with express, but when IE hits the "debugger" instruction, it asks me if I want to debug, and with wich tool. Visual studio is present in the list of options presented to me.

我不知道它是否适用于express,但当IE点击“调试器”指令时,它会询问我是否要调试,并使用wich工具。 Visual Studio出现在提供给我的选项列表中。

I don't know if express will be present for you though.

我不知道快递是否会出现在你面前。

"debugger" also works with firebug.

“调试器”也适用于firebug。

#2


5  

I just had this problem today as well. The debugger doesn't know where you script files are if you include them in the mvc view.

我今天也遇到了这个问题。如果将脚本文件包含在mvc视图中,则调试器不知道脚本文件的位置。

Put them in an external .js file (say default.js) in the scripts folder, add a script tag in the site.master and then you will hit your breakpoints.

将它们放在脚本文件夹中的外部.js文件(例如default.js)中,在site.master中添加脚本标记,然后您将点击断点。

#3


2  

VS JS debugging can work, but... Honestly, get Firebug. It's free, and does much, much more than the VS debugger.

VS JS调试可以工作,但是......老实说,得到Firebug。它是免费的,并且比VS调试器做得更多。

#4


1  

Here's my workaround for debugging javascript in MVC. VS2008 doesn't pick up on break points for javascript in an aspx page, but it will for a separate .js file. I create a debugJscript.js file when I'm working on a page. I create a reference to that debug page from my aspx page. I can step through javascript that way and then push the javascript code back to the aspx page when I'm happy with it.

这是我在MVC中调试javascript的解决方法。 VS2008没有在aspx页面中获取javascript的断点,但是它将用于单独的.js文件。我在页面上工作时创建了一个debugJscript.js文件。我从我的aspx页面创建了对该调试页面的引用。我可以通过这种方式逐步执行javascript,然后在我对它满意时将javascript代码推回到aspx页面。

You can avoid caching problems, too, on that external .js file if you refer to your file like so:

如果您像这样引用文件,也可以避免在外部.js文件上缓存问题:

    <script type="text/javascript" src="../../Scripts/DebugJScript.js?<%=DateTime.Now %>" ></script>    

#5


-1  

I don't use VS.Net Express, but in VS.Net Standard you can go to the Debug menu in your solution and choose "Attach to process". You will then get to choose the debug type: Native, Managed, or Script. Select Script, then select your process from the list. A list of scripts will now come up in your IDE. Click on script one you want to debug, throw in a breakpoint or two, and you should be ready to go.

我不使用VS.Net Express,但在VS.Net Standard中,您可以转到解决方案中的Debug菜单,然后选择“Attach to process”。然后,您将选择调试类型:Native,Managed或Script。选择脚本,然后从列表中选择您的流程。现在,IDE中将出现一个脚本列表。单击要调试的脚本,输入一两个断点,然后就可以开始了。

If MS has nerfed the Express version so that you can't attach to a process, then I guess you're stuck and will need the $$$ upgrade (which wouldn't entirely surprise me). Hey, what do you want for free? :)

如果MS已经对Express版本进行了监视,那么你就无法连接到一个进程,那么我猜你会被卡住并需要进行$$$升级(这并不会让我感到惊讶)。嘿,你想要什么免费的? :)