对于一个项目,我必须(不幸地)匹配一些确切的URL。ASP.Net MVC3:创建自定义URL,但不包含确切的控制器名称
所以我认为这不会是一个问题,我可以使用“MapRoute”来匹配网址与所需的控制器。但我无法让它工作。
我已经映射此网址:
http://{Host}/opc/public-documents/index.html
到
Area: opc
Controller: Documents
Action: Index
另一个例子是映射
http://{Host}/opc/public-documents/{year}/index.html
到
Area: opc
Controller: Documents
Action:DisplayByYear
Year(Parameter): {year}
我想这一点,whitout成功,在我区(ocpAreaRegistration.cs
):
context.MapRoute("DocumentsIndex", "opc/public-documents/index.html",
new {area="opc", controller = "Documents", action = "Index"});
context.MapRoute("DocumentsDisplayByYear", "opc/public-documents/{year}/index.html",
new {area="opc", controller = "Documents", action = "Action:DisplayByYear"});
但我得到了一些404错误:(当我试图访问它。我究竟做错了什么?
ocpAreaRegistration何时被调用?它应该由global.asax.cs中的'RegisterRoutes'调用 – podiluska 2012-08-06 12:25:40
不能为两个不同的路由使用相同的maproute id。在实际的代码中是这样吗? – cellik 2012-08-06 12:28:04
@cellik对不起,我只是在示例中,坏的复制粘贴 – J4N 2012-08-06 12:28:54