MVC 2 - URL 缩短/路由(地图路由)
我有一个 URL: http://localhost:XXXX/Details/569
我想将其缩短为: http://localhost:XXXX/569
目前我有:
routes.MapRoute(
"Default",
"{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
那么我在路线中做了哪些更改,以便何时输入一个整数值,它会转到 HomeController 中的“详细信息”函数:
public ActionResult Details(int recordID)
{
/** Code Here **/
return View();
}
编辑:捕获错误
另外,我如何捕获应用程序中发生的任何错误?我不想显示错误转储,而是想显示一条“好”消息,上面写着“哎呀!有东西坏了!”。
I have a URL: http://localhost:XXXX/Details/569
I want to shorten it to: http://localhost:XXXX/569
Currently I have:
routes.MapRoute(
"Default",
"{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
So what changes do I do in my routes so that when an integer value is entered, it goes to my Details function in the HomeController:
public ActionResult Details(int recordID)
{
/** Code Here **/
return View();
}
EDIT: Catching Errors
Also how can I catch for any error that happens in the application? Rather than display an error dump, I would like to show a "nice" message that says, "Oops! Something Broke!".
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将此路由添加到默认路由之前。它将确保仅包含数字的 URL 调用 HomeController 的详细信息操作。
Add this route before the default one. It will make sure the URLs containing only numbers calls HomeController's Details action.