我拥有最新版的Visual Studio 2019 16.5.4企业版。
我刚刚从模板创建了一个默认设置的ASP .Net Core 3.1 MVC应用程序。
然后,在首页的Index.cshtml中添加了一些JavaScript代码:
@{
ViewData["Title"] = "Home Page";
}
<div class="text-center">
<h1 class="display-4">Welcome</h1>
<p>Learn about <a href="https://learn.microsoft.com/aspnet/core">building Web apps with ASP.NET Core</a>.</p>
</div>
@section Scripts {
<script>
function GetJSON_Simple() {
var resp = [];
return resp;
}
debugger;
var simpleData = GetJSON_Simple();
</script>
}
我无法调试JavaScript代码(在GetJSON_Simple
函数体内或var simpleData = GetJSON_Simple()
上设置断点都没有被命中)。我已经尝试了Chrome和MS Edge (Chromium)。
根据这篇文章 (Debug JavaScript in dynamic files using Razor (ASP.NET) 部分):
在你想要断点的位置添加debugger;语句: 这会导致动态脚本停止执行并在创建时立即开始调试。
P.S. 我已经打开了Tools->Options->Debugging->General的Enable JavaScript Debugging for ASP.NET (Chrome and IE)复选框,并且当然我也是在Debug模式下编译的。
我的测试项目附在这里。
debugger;
代码行也可以工作了。步过,步入,转到定义都可以工作。不幸的是,我无法让编辑和继续工作 :( - bairog