使用MVC路由别名控制器 [英] Use MVC routing to alias a controller

查看:332
本文介绍了使用MVC路由别名控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为控制器 InstallationController ,以及安装看上报告重新presentation称的价目表的,但最终的用户坚持调用安装自己的价目表的。我想他看到URL 的http://网站/价目表/编辑/ 3 ,在此获得实际路由为<一个HREF =HTTP://网站/安装/编辑/ 3> HTTP://网站/安装/编辑/ 3 。我怎样才能做到这一点MVC 3 RC2?

I have a controller called InstallationController, and a fancy report representation of an installation called a Rate Card, but the end user insists on calling installations themselves Rate Cards. I would like him to see the URL http://site/RateCard/Edit/3, where this gets routed actually as http://site/Installation/Edit/3. How can I do this in MVC 3 RC2?

推荐答案

一对夫妇的选项,您可以重命名控制器 RateCardController ,或添加新的路由一个指向安装控制器,如:

A couple of options are, you can either rename the controller to RateCardController, or add a new route that directs to the Installation controller, like:

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

这篇关于使用MVC路由别名控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆