ASP.NET MVC - 来自 url 的 JQuery 调用没有任何操作无效

ASP.NET MVC - JQuery call from url without action not working

我有一个 http://localhost:54393/CreateTest/4fwp36 工作正常但是当我从 jQuery [=42] 调用 http://localhost:54393/CreateTest/RemoveControlsNew =] 那么如果有人可以帮助我,它就不会给出错误也不会调用控制器,因为我被困在这里超过 1 天

我已经试过了,但没用:

这是我的路由配置:

routes.MapRoute(
           name: "CreateTest",
           url: "CreateTest/{id}",
           defaults: new { controller = "CreateTest", action = "Index", id = UrlParameter.Optional }
       );

当我从另一个像这样调用它的控制器调用时,上面的代码工作得很好:

return Redirect("/CreateTest/"+ strTestID);

当我尝试使用 ajax post 方法调用同一个控制器时

RemoveControls: function (rid) {
    var MyAppUrlSettings = {
        MyUsefulUrl: "/CreateTest/RemoveControlsNew"
    }
    $.ajax({
        type: 'POST',
        dataType: "JSON",
        async: false,
        //url: '@Url.Action("RemoveControlsNew",Request.Url.Scheme)',
        url: MyAppUrlSettings.MyUsefulUrl,
        contentType: 'application/json; charset=utf-8',
        data: {
            rid: rid,
            bgcolor: CREATETEST.globalbgcolor,
            fontcolor: CREATETEST.globalfontcolor,
            fontsize: CREATETEST.globalfontsize
        },
        success:
            function (response) {
                var data = response;
                if (data == 'Error') {
                    CREATETEST.showerror('Some thing went wrong you cannot remove a question at the moment for selected option');
                }
                else {
                    $("#AddControlNew").load(location.href + " #AddControlNew");                       
                }
            },
        error:                
            function (response) {
                console.log(response);
                CREATETEST.showerror("Error: " + response);
            }
    });
},

然后这些都不起作用,我的方法没有被调用。

我收到这个错误:

Error on page

Controller code for Ajax call Regular Controller code

您的“页面错误”图像没有显示任何有用的信息,您是否收到 404202405 Header 状态代码

请post代码,而不是图片。

[FromBody] 属性应用于参数以从 HTTP 请求的 body 填充其属性。 ASP.NET 核心运行时将读取 body 的责任委托给输入格式化程序。

public JsonResult RemoveControlsNew([FromBody] int rid, string bgcolor, string fontcolor, string fontsize)