How can I programmatically check if a MVC Route exists?
Say I have this piece of code:
var virtualPath = base.GetVirtualPath(requestContext, routeValues);
I’d like to check if there’s a matching controller and action for the generated route at virtualPath.Route.
I tried with GetRouteData but it returns null even for valid routes.
You can get RouteValueDictionary from
virtualPath, then use reflection to check if exists controller and action for this routevaluesUpdate:
Sample method (I try it. It works):