我喜欢创建注册这样的路线:
User/{^[a-zA-Z]+$}/{controller}/{action}/{id}
这就是网址的样子:
/User/myUser/Product/Action
所以我在AreaRegistration中注册了一条路线。约束应该只允许单词。
context.MapRoute(
"Customer_Default",
"User/{^[a-zA-Z]+$}/{controller}/{action}/{id}",
new { action = "Index", id = UrlParameter.Optional }
);
RedirectToAction
路线重定向到此?答案 0 :(得分:1)
您需要使用constraints
MapRoute()
参数
context.MapRoute(
"Customer_Default",
"User/{username}/{controller}/{action}/{id}",
new { action = "Index", id = UrlParameter.Optional },
constraints: new { username= @"^[a-zA-Z]+$" }
);
那你的行动就是这样:
public ActionResult ActionName(string username, int id)
答案 1 :(得分:0)