这称为“条状路线”。实现此目的的一种方法是使用可选
slug参数定义路由,并在控制器方法中检查是否已提供参数
routes.MapRoute( name: "Question", url: "Question/{id}/{slug}", defaults: new { controller = "Question", action = "Details", slug = UrlParameter.Optional });然后输入
QuestionController(假设将始终提供ID)
public ActionResult Details (int id, string slug){ if (string.IsNullOrEmpty(slug)) { // Look up the slug in the database based on the id, but for testing slug = "this-is-a-slug"; return RedirectToAction("Details", new { id = id, slug = slug }); } var model = db.Questions.Find(id); return View(model);}


