首先在Golbal文件中注入
protected void Application_Start(object sender, EventArgs e)
{
RegisterRoutes(RouteTable.Routes);
}
routes.MapRouteWithName("Company_Detail",//路由名称
ApplicationInfo.RouteStartPath + "{Path1}/{CompanyId}/{Path2}",//路由路径的模式,{path}是作为站位付
ApplicationInfo.LoadControlPath,//默认的文件或者说默认文件的物理路径
false,
new RouteValueDictionary { { "Path1", "Company" }, { "Path2", "Detail" }, { "CompanyId", "" } },//默认的路径,就相当于Path1=Company,把前面的占位符填充进你你设置的路由路径值
new RouteValueDictionary { { "Path1", "Company" }, { "Path2", "Detail" }, { "CompanyId", "[0-9]+" } });//这里设置路由值得格式,example:“{ "CompanyId", "[0-9]+" }” 这里是设置"CompanyId"这个占位符只能是数字。
这个是设定路由的方法