下面是我在mvc4应用程序中的routeconfig.cs文件
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{bizId}",
defaults: new { controller = "Home", action = "Index", bizId = UrlParameter.Optional }
);
routes.MapRoute(
"Outlet",
"Outlet/{bizId}",
new { controller = "Home", action = "Index" },
new { bizId = UrlParameter.Optional }
);
}
当我运行应用程序时,我需要在本地主机端口后输入/Home/Index?bizId=1 或任何 Id 才能运行我的应用程序。它运行良好。但是,现在作为第二个route.maproute,我希望网址显示为例如: localhost:49787/Outlet?bizId=1 但这不起作用。请帮忙!提前致谢
最佳答案
已修复:
routes.MapRoute(
name: "Outlet",
url: "Outlet/{bizId}",
defaults: new { controller = "Home", action = "Index", bizId = 1 }
);
关于asp.net-mvc-4 - 在mvc 4中的routeconfig.cs中设置自定义路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16835848/