Sunday, 15 August 2010

asp.net mvc 5 - Why doesn't my named route work? -


itemprop = "text">

Standard MVC 5 template.
That's why I'm trying to understand and create a named route to be used in this way:

  & lt; A href = "@ Url.RouteUrl (Route name:" myroute ", root value: new {code =" 123 "}) This link should be linked to & lt; / a & gt;  

In Home Controller: [Route ("Home / DOIT", name = "Myroft", HTTP GATE] Public Action Result DOIT (String Code)) {See Return () ;}

MvcAttributeRouting is definitely enabled in RoutConfig.cs:

  public static zero register routs {routes.IgnoreRoute ("{ Resource} AXD / {* pathInfo} "); Routes.MapRoute (name:" default ", url:" {controller} / {action} / {id} ", d Fault: New {Admin = "Home", Action = "Index", ID = UrlParameter.Optional}); routes.MapMvcAttributeRoutes ();}  

Because if it was not enabled One will get:

A path named 'myroute' was not found in the path collection. Name of the parameter: Name

But I'm getting:

The resource can not be found. Description: HTTP 404. The resource you are looking for (or one of its dependencies), could be renamed, or temporarily The Uplbd may please review the following URL and make sure that it is spelled correctly.

Requested URL: / Home / IOT

What am I doing? Edit: Of course, I'm doing something wrong in the root attribute, because it also does not work:

  [root ("doit")]  / Code>  

or

  [root ("Home / DOIT")]  

Both give me 404, request URL's Regardless of

command In which you have the MapMvcAttributeRoutes line is important, you must have the wrong place before it should be called before the default route.

  public class root config {public static zero registrations (routes collection path) {routes.IgnoreRoute ("{resource} .axd / {* pathInfo}"); // Add it to get specialty routes to work routes. MapMvcAttributeRoutes (); Routes.MapRoute (name: "default", url: "{controller} / {action} / {id}", default: new {controller = "home", action = "index", id = urlparameter.option}}; }}  

Routing functions like a switch case statement First matches the match but if you first enter the default route, then it 0, 1, 2 Or will match every URL with 3 segments and effectively override any particular route of those lengths.

Reference:


No comments:

Post a Comment