2

我有一个网址:http://localhost:XXXX/Details/569

我想将其缩短为:http://localhost:XXXX/569

目前我有:

routes.MapRoute(
    "Default",
    "{controller}/{action}/{id}",
    new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);

那么我在路由中做了哪些更改,以便在输入整数值时,它会转到 HomeController 中的 Details 函数:

public ActionResult Details(int recordID)
{
    /** Code Here **/
    return View();
}

编辑:捕捉错误

另外,我如何捕捉应用程序中发生的任何错误?我不想显示错误转储,而是想显示一条“不错的”消息,上面写着“哎呀!坏了!”。

4

1 回答 1

3

在默认路由之前添加此路由。它将确保仅包含数字的 URL 调用 HomeController 的 Details 操作。

routes.MapRoute(
    "RecordDetails",
    "xxxx/{RecordID}",
    new { controller = "Home", action = "Details", RecordID=0 },
    new { RecordID = @"\d+" });
于 2011-01-29T19:19:42.167 回答