Switching to {controller}/{id}/{action} breaks RedirectToAction

后端 未结 6 1905
后悔当初
后悔当初 2021-01-04 23:55

I am trying to use proper REST urls with MVC. To do that I switched default Routing from:

{controller}/{action}/{id}
6条回答
  •  生来不讨喜
    2021-01-05 00:48

    I had a similar problem and was able to solve it by adding the id to the default route as well.

    routes.MapRoute(
        "Default", 
        "{controller}/{action}/{id}", 
        new { controller = "Home", action = "Index", id = UrlParameter.Optional });
    

    If there is truly no id in your default route then you could also try:

    routes.MapRoute(
        "Default", 
        "{controller}/{action}", 
        new { controller = "Home", action = "Index", id = string.Empty });
    

提交回复
热议问题