我有一个名为 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/