Enrutamiento específico para diferentes controladores
Frecuentes
Visto 38 veces
0
Can I have different routes which will be activated upon different controllers ? For example If I have controller "Age" this controller to accept this kind of routing.
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/age",
defaults: new { controller = "Home", action = "Index", age = UrlParameter.Optional }
);
If I have another controller for example "Name" to accept this kind of routing.
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/name",
defaults: new { controller = "Home", action = "Index", name = UrlParameter.Optional }
);
1 Respuestas
0
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Name", // Route name
"Name/{action}/{id}", // URL with parameters
new { controller = "Name", action = "Index" } // Parameter defaults
);
A custom route for your NameController.
There are different samples at asp.net
respondido 27 nov., 13:08
No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas c# asp.net-mvc asp.net-mvc-routing or haz tu propia pregunta.
In the first example you will pass age as an id to every action on every controller? What have you tried, and what do you want to achive? - scheien
I want every controller to run with different routing. For example when Age/Index/0 run in the Index method paramter to be "int age". When Name/Index/0 run the paramter of the Index method to be "name". - theChampion