JQuery Ajax调用被解析为当前的Controller文件夹,而不是根文件夹

Gra*_*ton 2 asp.net-mvc jquery

我想我在JQuery和ASP.NET MVC中发现了一些非常奇怪的东西.

正如在这个问题中提到的,我有以下JQuery代码:

$(function() {
$("#username").click(function() {
        $.getJSON("ViewRecord/GetSoftwareChoice", {username:'123'},
    function(data) {
        alert(data);
    });
    });
});
Run Code Online (Sandbox Code Playgroud)

ViewRecord是控制器,GetSoftwareChoice是动作方法.但为此生成的URl是

http://localhost/ViewRecord/ViewRecord/GetSoftwareChoice?username=123
Run Code Online (Sandbox Code Playgroud)

太神奇了,不是吗?

为什么会这样?

这是我的路线:

        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.MapRoute(
            "Default",                                              // Route name
            "{controller}/{action}/{id}",                           // URL with parameters
            new { controller = "Home", action = "Index", id = "" }  // Parameter defaults
        );
Run Code Online (Sandbox Code Playgroud)

Jav*_*ier 9

如果没有前导斜杠,则URL的路径是本地路径,并且相对于页面路径进行解析.就像您可能放入HTML中的任何其他URL一样.