We are working with an asp.net mvc app that is shared by multiple clients. We need the urls to include the clients url friendly name. For example:
domain.com/clientName/controller/action/id
This below appears to be working when it comes to routing, but the “clientName” is not generated correctly for the action link helpers.
_routes.MapRoute("DefaultRoute",
"{clientName}/{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = string.Empty },
new { clientName = @"[\w-]+" });
We would like to continue using the Html.ActionLink Helper methods, but it does not include the clientName in the generated link. Do we have to write our own helpers in this scenario or is there an alternative approach?
Has anyone else built an application with this type of routing scenario? Any suggestions would be appreciated!
What you are trying to do should work without having to use RouteLink or specifying an anonymous object. Make sure your route registrations are correct. For example, if you have something like:
before your DefaultRoute, it can cause calls to ActionLink to return strange results. I’ve been burned by this before.