views:

89

answers:

2

I have two routes in my ASP.NET MVC application.

The first is working fine - it's an ActionResult that returns a view.

The second is on the same controller and is an ActionResult that returns a Json response. It takes a couple of additional paramaters.

This second route is working on my dev machine, but when I deploy it to the server I get back a blank response. Any suggestions will be gratefully received.

I have also copy-pasted the route into a browser to eliminate any issues in the jQuery JavaScript.

The method

    [HttpGet]
    public ActionResult CheckSku(string id, string brand)
    {
        CheckSkuModel model = new CheckSkuModel();

        model.Id = id;
        model.Brand = brand;

        return Json(model, JsonRequestBehavior.AllowGet);
    }

The routes

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

        routes.MapRoute(
            "CheckSku",                                              // Route name
            "{controller}.mvc/{action}/{id}/{brand}",                           // URL with parameters
            new { controller = "Orders", action = "CheckSku", id = "", brand = "" }  // Parameter defaults
        );
+1  A: 

Hi,

Two thing you can quickly check that may help: 1. Swap the two routes around so "CheckSku" is above "default" 2. Make the "CheckSku" more specific so will look something like:

routes.MapRoute(
        "CheckSku",                                              // Route name
        "Orders.mvc/CheckSku/{id}/{brand}",                           // URL with parameters
        new { controller = "Orders", action = "CheckSku", id = "", brand = "" }  // Parameter defaults
    );

that was another controller doesn't pick up the url by mistake.

An alternative is the use the routelink helper when generating the url so it points to the correct route.

Simon G
RouteLink was definitely the way to go for this - I used it and everything now works. Thank you.
Sohnee
A: 

When you say you "get back a blank response", do you mean you're not getting an error, but that the server isn't returning anything? What makes you think this is a routing issue?

Some troubleshooting tips:

  1. Use Fiddler to examine the HTTP request you're making and the raw HTTP response the server is sending back. If you're getting a 500 response code then check the response for error information.

  2. Can you attach a remote debugger to the server? This might give you a chance to investigate any exceptions that are raised.

Seth Petry-Johnson
I used Firebug to determine that the response was a 200 "OK" response already. There is no error - the response is empty, i.e. no json-serialised data. I'm guessing it is a routing issue as if the request made it to the controller / action, it would not be possible for the response to be 200 AND blank.
Sohnee