jQuery Ajax调用被解析为当前的Controller文件夹,而不是根文件夹 [英] JQuery Ajax call gets resolved to the current Controller Folder, Instead of root Folder

查看:151
本文介绍了jQuery Ajax调用被解析为当前的Controller文件夹,而不是根文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为我在JQuery和ASP.NET MVC中发现了一些很奇怪的东西.

I think I found something very weird in JQuery and ASP.NET MVC.

As mentioned in this question, I have the following JQuery code:

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

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

ViewRecord is the controller and GetSoftwareChoice is the action method. But the URl generated for this is

http://localhost/ViewRecord/ViewRecord/GetSoftwareChoice?username=123

太神奇了,不是吗?

为什么会这样?

这是我的路线:

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

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

推荐答案

(不带斜杠),URL的路径是本地路径,并且相对于页面的路径进行解析.就像您可以在HTML中放入的其他任何URL一样.

without a leading slash, the URL's path is a local path and it's resolved relative to the page's path. just like any other URL that you might put into your HTML.

这篇关于jQuery Ajax调用被解析为当前的Controller文件夹,而不是根文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆