简体   繁体   English

收到MVC路由问题404

[英]MVC Routing issue 404 received

I am trying to call an action method through ajax but am getting a 404. To illustrate, the following is my ajax: 我试图通过ajax调用一个动作方法,但是却得到了404。为说明起见,以下是我的ajax:

  $.ajax({
            type: "GET",
            url: "/Product/LandingPage",
            data: {trackingCode: trackingCode, productId: productId},
            success: function (data) {
                alert("I worked!");
            }
        });

From alerting out the paramters I can see both trackingCode and productId are being successfully set so that's not the issue. 通过警告参数,我可以看到trackingCode和productId已成功设置,所以这不是问题。 I thought, to test this, I should be able to direclty call the URL like so: 我认为,要对此进行测试,我应该可以像这样直接调用该URL:

http://www.mywebsite.com/Product/LandingPage?trackingCode=fgdfg&productId=213456

However, when I try that I get a 404 error, so maybe the routing isn't working. 但是,当我尝试得到404错误时,路由可能无法正常工作。 I've added the following route: 我添加了以下路线:

            routes.MapRoute(
           "Product_LandingPage",
           "Product/LandingPage",
           new { controller = "Product", action = "LandingPage" }, new {  trackingCode = UrlParameter.Optional ,productId = @"\d+" });

But I still get a 404. This is my Product controller method: 但是我仍然得到404。这是我的产品控制器方法:

 [AcceptVerbs(HttpVerbs.Get | HttpVerbs.Head)]
    public ActionResult LandingPage(string trackingCode, int productId)
    {
        //Some magic in here
    }

I've a feeling I'm missing something obvious here. 我感觉我在这里缺少明显的东西。 Any ideas as to why I'm getting a 404? 关于为什么我要404的任何想法?

Note this could be some other code causing an issue, I just want to sanity check what I'm doing to rule out a stupid mistake on my part. 请注意,这可能是导致问题的其他代码,我只想检查我在做什么,以排除我自己的愚蠢错误。

Using Phil Haacks route debugger I found the issue, it was caused by another route, higher up the chain of route command. 使用Phil Haacks路由调试器,我发现了这个问题,它是由另一条路由引起的,位于路由命令链的上层。 Restructuring has sorted this out. 重组已经解决了这一问题。 Thanks for all help. 感谢您的所有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM