我有以下路线:

routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(null,"Conference/{shortName}/Submission/{submission}/{action}", new { controller = "Conference", action = "Show" });
routes.MapRoute(null,"Conference/{shortName}/{action}",new { controller = "Conference", action = "Index" });
routes.MapRoute("Default", "{controller}/{action}/{id}", new { controller = "Home", action = "Index", id = UrlParameter.Optional }
        );


以下(希望是显而易见的)链接都正常工作:


/会议/ testconf
/会议/ testconf / ShowSubmissions
/会议/ testconf /提交/ firstSub
/会议/ testconf /提交/ firstSub / EditSubmission


当我现在进入Submission / firstSub并创建一个像这样的ActionLink时

@Html.ActionLink("Show Submissions", "ShowSubmissions", "Conference", new { shortName = Model.confereceShortName },null)


它创建以下链接


/会议/ testconf /提交/ firstSub / ShowSubmissions


我该如何在不进行硬编码的情况下让actionlink忘记Submission / firstSub?

最佳答案

您在哪里有{controller}的占位符?

默认路由应类似于以下示例。

 routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                "Default", // Route name
                "{controller}/{action}/{*id}", // URL with parameters
                new {controller = "Home", action = "Index", id = UrlParameter.Optional} // Parameter defaults
                );


另外,请尝试在第一条路线中删除/ Submission /部分。
有关自定义路线创建和订购的帖子的链接:

1)Creating Custom Routes (C#)

2)Custom routing for ASP .NET MVC

3)official source from asp.net mvc

10-06 02:52