ActionResult parameter is always zero
I am trying to define RouteAttribute in my controller, but the value is always null. Stuff I tried:
[HttpGet]
[Route("User/ChangePassword/{code:guid}")]
public ActionResult ChangePassword(Guid code)
{
return View();
}
URL:
http://localhost:59635/User/ChangePassword/c809619-4451-4e60-86ca-3bf7159c6d15
I get this code always null even if I put in a string. Ps. Parameter and optional ideas required?
+3
source to share
1 answer
Make sure your call to register the attribute routes precedes the registration of the default routes (or scope). It should look something like this ...
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapMvcAttributeRoutes();
AreaRegistration.RegisterAllAreas();
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = "" } // Parameter defaults
);
+3
source to share