I have several controllers for widgets named {WidgetName}WidgetController, e.g. SampleWidgetController. I need to create a route which catches all requests to such controllers and passes them to one common controller together with requested controller's name and action.
public class SampleWidgetController : Controller
{
public ActionResult Content()
{
...
}
}
public class CommonController : Controller
{
public ActionResult Content(string controllerName, string actionName)
{
// I want all requests to SampleWidget/Content to be passed here
// With controllerName = "SampleWidget" and actionName = "Content"
}
}
I can create a custom RouteConstraint to accept only those controllers that have 'Widget' suffix, but I have a problem with defining the route itself which will pass the requested controller's name and action to the common controller.