I have created a page route so I can integrate my MVC application with a few WebForms pages that exist in my project:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
// register the report routes
routes.MapPageRoute("ReportTest",
"reports/test",
"~/WebForms/Test.aspx"
);
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
This has created a problem whenever I use Html.ActionLink in my Views:
<%: Html.ActionLink("Home", "Index", "Home") %>
When I load the page in the browser the link appears like:
http://localhost:12345/reports/test?action=Index&controller=Home
Has anyone run into this before? How can I fix this?
My guess is that you need to add some parameter options to the MapPageRoute
declaration. So if you have more than one webforms page in the WebForms
directory this works well.
routes.MapPageRoute ("ReportTest",
"reports/{pagename}",
"~/WebForms/{pagename}.aspx");
PS: You may also want to have a look at the RouteExistingFiles
property of RouteCollection
An alternative would be to use
<%=Html.RouteLink("Home","Default", new {controller = "Home", action = "Index"})%>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With