I am trying to use the correct REST URLs with MVC . To do this, I turned off the default routing from:
{controller}/{action}/{id}
to
{controller}/{id}/{action}
therefore instead of:
/Customer/Approve/23
now exists
/Customer/23/Approve
ActionLink seems to work fine, but the following code in the CustomerController:
[CustomAuthorize] [HttpGet] public ActionResult Approve(int id) { _customerService.Approve(id); return RedirectToAction("Search");
ends with URL /Customer/23/Search . While he has to go /Customer/Search . Somehow he recalls 23 (id) .
Here is my routing code in global.cs
routes.MapRoute( "AdminRoute", // Route name "{controller}/{id}/{action}", new { controller = "Home", action = "Index", id = UrlParameter.Optional }, new { id = new IsIntegerConstraint() } ); routes.MapRoute( "Default", "{controller}/{action}", new { controller = "Home", action = "Index" });
If I switch two functions, RedirectToAction will start working, but using:
Html.ActionLink("Approve", "Approve", new { Id = 23})
Now generates /Customer/Approve?id=23 instead of /Customer/23/Approve .
I could specify direct URLs like ~/Customer/23/Approve instead of using ActionLink and RedirectToAction , but would prefer to stick with the functions provided by MVC .
Eric P
source share