views:

63

answers:

1

Hi there, I have two pages in my simple MVC App with two defined routes:

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

I needed to have the results page load with just a product ID such as this: [MyDomain....]/Results/12345. But also the main page does a POST (using JQuery) to the Results Controller for updates using this route: [MyDomain....]/Main/Update along with a data bag. This works fine when I only have the "Default" route. But when I added the other "Results" route, all the POST calls to update are failing. Any ideas what I'm doing wrong???

Thanks a lot.

A: 

I didn't try this out, but should accomplish what you need. Not sure if there may be a "better" way to accomplish it.

routes.MapRoute(
  "Results", // Route name
  "Results/{id}", // URL with parameters
  new { controller = "Results", action = "Index", id = "" } // Parameter defaults
  new { id = @"\d+" } // regex for id param - id must be a number
);
routes.MapRoute(
  "Default", // Route name
  "{controller}/{action}/{id}", // URL with parameters
  new { controller = "Main", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
Nate Pinchot
It worked!!! Thanks so much for your help.
Robert