gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 01:50:10 25 4
gpt4 key购买 nike

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com