我在Global.asax.cs中有以下URL地图:
routes.MapRoute("RejectRevision", "{controller}/{Index}/{revisionId}"
, new { controller = "RejectRevision", action = "Index", revisionId = "" });
但我不想输入http://localhost:9999/RejectRevision/Index/1,我希望能够输入http://localhost:9999/RejectRevision/1以便在RejectRevision控制器上点击Index操作。我在这里缺少什么?
感谢。
答案 0 :(得分:1)
将它放在Default
路线之前:
routes.MapRoute(
"RejectRevision",
"{controller}/{revisionId}",
new {
controller = "RejectRevision",
action = "Index",
revisionId = UrlParameter.Optional }
);
如果将其放在Default
路线之前,则/RejectRevision/1
的请求将映射到RejectRevisionController.Index()
操作方法。
或者,如果这是您希望像这样映射的唯一Controller / Action方法,那么您可以使用文字而不是路径的参数:
routes.MapRoute(
"RejectRevision",
"RejectRevision/{revisionId}",
new {
controller = "RejectRevision",
action = "Index",
revisionId = UrlParameter.Optional }
);