62,046
社区成员
发帖
与我相关
我的任务
分享
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default", //路由名称
"{controller}/{action}/{id}", //带有参数的 URL
new { controller = "Home", action = "Index", id = UrlParameter.Optional } //参数默认值
);
}
Areas 内的,如下
public class BaseInformationAreaRegistration : AreaRegistration
{
public override string AreaName
{
get
{
return "BaseInformation";
}
}
public override void RegisterArea(AreaRegistrationContext context)
{
/*context.MapRoute(
"BaseInformation_default",
"BaseInformation/{controller}/{action}/{id}",
new { action = "Index", id = UrlParameter.Optional }
);*/
context.MapRoute(
this.AreaName + "_Default",
this.AreaName + "/{controller}/{action}/{id}",
new { area = this.AreaName, controller = "Home", action = "Index", id = UrlParameter.Optional },
new string[] { "WebApp.Areas." + this.AreaName + ".Controllers" }
);
}
}