Question

how do I make this route works:

        routes.MapRoute(
            name: "Custom",
            url: "{modality}/{controller}/{action}/{id}",
            defaults: new {controller = "Home", action = "Index", id = UrlParameter.Optional }
        );

        routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
        );

I need to call if I want this:

/ModalityName/SomeController/SomeAction/SomeId

or

/SomeController/SomeAction/SomeId

but the second route that is the default from mvc is not working.

I just need some times to inform the modality so I can get some content based on that

Was it helpful?

Solution

Routes are evaluated for a match to an incoming URL in order

routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

routes.MapRoute(
    name: "Custom",
    url: "ModalityName/{controller}/{action}/{id}",
    defaults: new
    {
        controller = "ModalityName",
        action = "action",
    }
);



routes.MapRoute(
    name: "Default",
    url: "{controller}/{action}/{id}",
    defaults: new { 
        controller = "Home", 
        action = "Index", 
        id = UrlParameter.Optional }
);

}

More Information Read Link :http://www.codeproject.com/Articles/641783/Customizing-Routes-in-ASP-NET-MVC

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top