Enrutamiento específico para diferentes controladores

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 }
    );

preguntado el 27 de noviembre de 13 a las 07:11

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? -

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". -

1 Respuestas

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 or haz tu propia pregunta.