Is there a way to use RedirectToAction or something equivalent in a ASP.Net Forms page?
I have a mixed environment with both Forms and MVC v2 pages. I want to redirect to a MVC page from a Forms page.
Usually I use RedirectToAction when within the controller. But when I am in a Asp.Net Forms type page I can't really 开发者_如何学Gouse that.
I'm digging around the framework to find a solution, thought I would ask here in case someone already knows the answer to this.
I found the answer on my own. Here is how I solved this:
var controllerName = "NameOfMyController";
var actionName = "NameOfMyAction";
//Lets resolve the URL for the controller/action based on the existing routes
var routes = RouteTable.Routes;
var virtualPathData = routes.GetVirtualPath(
null,
new RouteValueDictionary {
{"Controller", controllerName},
{"Action", actionName}
});
/* resolvedUrl should now contain the full URL to
the controller/action defined at the beginging */
var resolvedUrl = virtualPathData == null ? "" : virtualPathData.VirtualPath;
精彩评论