如何在 MVC3 中创建简单的路由?
我正在 MVC3 中编写一个短 url 服务,部分作为学习工具。
当我加载网址 http://mysite/abc 时,我想重定向到控制器中具有以下签名的操作:
public ActionResult RedirectToLink(string shortLink)
我将如何创建一条路线来运行此代码?我已经尝试过以下方法:
routes.MapRoute("Link", "{shortLink}", new { controller = "LinkController", action = "RedirectToLink" });
或者,如果有人可以向我指出一本不错的 MVC3 入门书,它实际上涵盖了基础知识,而不是自上一个版本以来发生的更改,并且涵盖了这种情况,我将非常感激。
谢谢
I am writing a short url service in MVC3, partly as a learning tool.
When I load the url http://mysite/abc I want to redirect to an action in my controller with the following signature:
public ActionResult RedirectToLink(string shortLink)
How would I create a route in order to run this code? I have tried the following:
routes.MapRoute("Link", "{shortLink}", new { controller = "LinkController", action = "RedirectToLink" });
Alternatively, if someone can point me towards a decent primer for MVC3 that actually covers the basics rather than what's changed since the last version and would cover this scenario, I'd be much obliged.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是您想要的路线:
this is the route your want :