MVC的MapPageRoute和ActionLink的 [英] MVC MapPageRoute and ActionLink
问题描述
我创建了一个页面的路线,所以我可以与存在于我的项目数的WebForms页我的MVC应用程序集成:
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 }
);
}
这创造,每当我在视图中使用Html.ActionLink一个问题:
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?
推荐答案
我的猜测是,你需要一些参数选项添加到的MapPageRoute
声明。所以,如果你在的WebForms
目录中有多个web表单页面这个效果很好。
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:你可能也想看看的 RouteExistingFiles
属性 RouteCollection
另一种方法是使用
<%=Html.RouteLink("Home","Default", new {controller = "Home", action = "Index"})%>
这篇关于MVC的MapPageRoute和ActionLink的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!