我喜欢创建这样的注册路径:
User/{^[a-zA-Z]+$}/{controller}/{action}/{id}
URL应该是这样的:
/User/myUser/Product/Action
所以我在AreaRegistration上注册了一条路线。这种约束只允许使用单词。
context.MapRoute(
"Customer_Default",
"User/{^[a-zA-Z]+$}/{controller}/{action}/{id}",
new { action = "Index", id = UrlParameter.Optional }
);RedirectToAction路由重定向到此?发布于 2015-02-25 10:47:44
您需要使用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)发布于 2015-02-25 10:48:59
https://stackoverflow.com/questions/28716393
复制相似问题