asp.net mvc - How to register minimum routes for similar actions? -
i have actions:
public partial class mycontroller : controller { public actionresult action1() { } public actionresult action2(int id) { } public actionresult action3(string id) { } public actionresult action4(string name) { } } do need register routes each action this:
routes.maproute("r1", "{controller}/{action}/{id}", new { id = urlparameter.optional }); routes.maproute("r2", "{controller}/{action}/{name}", new { name = urlparameter.optional }); or there way register 1 pattern route actions or maybe need kind of "hack"?
similar urls should use similar routes. in case have single url pattern /controller/action/someid. use default route:
routes.maproute( "default", "{controller}/{action}/{id}", new { controller = "home", action = "index", id = urlparameter.optional } ); and update actions:
public partial class mycontroller : controller { public actionresult action1() { } public actionresult action2(int id) { } public actionresult action3(string id) { } public actionresult action4(string name) { } } as far last action concerned name parameter passed query string. if insist on being part of path, rename id. better pass arbitrary strings such names query string parameters , not part of url paths.
Comments
Post a Comment