asp.net-mvc - 使用 MVC 路由为 Controller 设置别名

标签 asp.net-mvc routing asp.net-mvc-routing asp.net-mvc-3

我有一个名为 InstallationController 的 Controller ,以及一个名为“价目表”的装置的精美报告表示,但最终用户坚持要求自己将装置称为价目表。我想让他看到 URL http://site/RateCard/Edit/3 ,这实际上被路由为 http://site/Installation/Edit/3 .我怎样才能在 MVC 3 RC2 中做到这一点?

最佳答案

有几个选项,您可以将 Controller 重命名为 RateCardController ,或者添加一个指向安装 Controller 的新路由,例如:

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

关于asp.net-mvc - 使用 MVC 路由为 Controller 设置别名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4464934/

相关文章:

asp.net-mvc - 强制所有区域使用相同的布局

asp.net-mvc - 路由测试 ASP.NET MVC4

asp.net - MVC5身份验证中的“Trust relationship between … and the primary domain failed”

c# - 邮政添加自定义 header

asp.net - 如何以编程方式设置 Elmah 电子邮件的收件人

asp.net-mvc - ASP.NET MVC-生成没有Http/请求上下文的路由

asp.net - ASP.NET Web 应用程序程序集能否在运行期间被替换

c# - 如何确定任意 URL 是否与定义的路由匹配

angular - 为什么 routerLink 和 router.navigate() 行为不同?

Asp.NET MVC 2 路由