Search code examples
asp.net-mvcmodel-view-controllerroutesasp.net-mvc-routing

adding and calling company names in routes mvc


I am implementing the way discussed in the following thread: Adding company name in Routes mvc 4

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

but how to call this i.e. Company2/Home/Index from code on another action ?

Currently, I am using return RedirectToAction("Index", "Home") but want to add Company2 in it and redirect dynamically.


Solution

  • You just need to add CompanyName to the route values.

    return RedirectToAction("Index", "Home", new { CompanyName = "Company2" });