【发布时间】:2014-08-13 16:06:57
【问题描述】:
我在 MVC5 中的默认路由之前定义了一个自定义路由,但由于某种原因它没有被命中。它到达了默认路由。
我的路线定义如下:
routes.MapRoute(
name: "PDF Viewer",
url : "pdf/{id}",
defaults : new { controller = "PdfViewer", action = "Index", id = UrlParameter.Optional },
namespaces : new[] { "App.Web.Controllers" }
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults : new { controller = "Calendar", action = "Index", id = UrlParameter.Optional },
namespaces : new[] { "App.Web.Controllers" }
);
当导航到/pdf/1 时,它不会被路线捕获。 Route Debugger 显示如下结果:
【问题讨论】:
-
当你尝试
/PdfViewer/Index/1? -
好的,好主意。使用该 URL 时,它仍然返回服务器错误,但是当我调试时,我的
HandleError属性或Global.asax Application_Error事件中没有任何错误 -
是 404(未找到)还是 500(服务器错误)?
-
@haim770 哈!不知道发生了什么,可能是缓存问题,但我清除了浏览器缓存并再次尝试,然后它实际上在 Global.asax 中发现了错误。这是错误
"The current request for action 'Index' on controller type 'PdfViewerController' is ambiguous between the following action methods: App.Web.Controllers.PdfViewerController.Index() and App.Web.Controllers.PdfViewerController.Index(Int32)"。我不明白,我在网址中传递了Int32。 -
传递给
Index(int32 ...)的参数的名称是什么?
标签: c# asp.net-mvc routes asp.net-mvc-5 routedebugger