using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
namespace MvcRazorDemo
{
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
//路由规则:
//1、可以有多条路由规则
//2、路由规则是有顺序的。前面被匹配了之后,后面就没有机会了。
routes.MapRoute(
name: "Default2",//作为路由规则的key,一定不能重复
url: "{controller}-{action}/{id}",//请求后台URL规则
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }//,//默认值
//constraints: new { controller=@"^\w+$",id=@"^\d+$"},//约束
//namespaces: new string[] { "MvcRazorDemo.Controllers" }//控制器命名空间的约束
);
//注册一条路由规则
routes.MapRoute(
name: "Default",//作为路由规则的key,一定不能重复
url: "{controller}/{action}/{id}",//请求后台URL规则
//http://localhost:23017/Home-Index
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }//,//默认值
//constraints: new { controller=@"^\w+$",id=@"^\d+$"},//约束
//namespaces: new string[] { "MvcRazorDemo.Controllers" }//控制器命名空间的约束
);
//routes.MapRoute(
// "酒店列表页",//路由规则名字
// "hotels/{action}-{city}-{price}-{star}", //路由规则的URL格式
// new { controller = "Hotel", action = "list", city = "beijing", price="-1,-1", star="-1" },//默认值
// new { city=@"[a-zA-Z]*",price=@"(\d)+\,(\d)+", star="[-1-5]"}
//);
hotels/所有匹配
//routes.MapRoute(
// "酒店首页",
// "hotels/{*写什么都可以}",
// new { controller = "Hotel", action = "default", hotelid = "" }
//);
//routes.MapRoute(
// "网站首页",
// "{*values}",
// new { controller = "Home", action = "index"}
//);
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
namespace MvcRazorDemo
{
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
//路由规则:
//1、可以有多条路由规则
//2、路由规则是有顺序的。前面被匹配了之后,后面就没有机会了。
routes.MapRoute(
name: "Default2",//作为路由规则的key,一定不能重复
url: "{controller}-{action}/{id}",//请求后台URL规则
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }//,//默认值
//constraints: new { controller=@"^\w+$",id=@"^\d+$"},//约束
//namespaces: new string[] { "MvcRazorDemo.Controllers" }//控制器命名空间的约束
);
//注册一条路由规则
routes.MapRoute(
name: "Default",//作为路由规则的key,一定不能重复
url: "{controller}/{action}/{id}",//请求后台URL规则
//http://localhost:23017/Home-Index
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }//,//默认值
//constraints: new { controller=@"^\w+$",id=@"^\d+$"},//约束
//namespaces: new string[] { "MvcRazorDemo.Controllers" }//控制器命名空间的约束
);
//routes.MapRoute(
// "酒店列表页",//路由规则名字
// "hotels/{action}-{city}-{price}-{star}", //路由规则的URL格式
// new { controller = "Hotel", action = "list", city = "beijing", price="-1,-1", star="-1" },//默认值
// new { city=@"[a-zA-Z]*",price=@"(\d)+\,(\d)+", star="[-1-5]"}
//);
hotels/所有匹配
//routes.MapRoute(
// "酒店首页",
// "hotels/{*写什么都可以}",
// new { controller = "Hotel", action = "default", hotelid = "" }
//);
//routes.MapRoute(
// "网站首页",
// "{*values}",
// new { controller = "Home", action = "index"}
//);
}
}
}