微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

asp.net-mvc – 如何使用“?”路由查询字符串以及如何处理它

在我的全局asax文件中,我想映射一个这样的路由:
http://domain.com/add/link?url=http%3A%2F%2Fgoogle.com

然后使用我的LinkController和名为Add的操作捕获它.

我这样做吗?

global.asax->

routes.MapRoute(
    "AddLink","Add/Link?{url}",new { controller = "Link",action = "Add" }
);

LinkController->

public string Add(string url)
{
    return url; // just want to output it to the webpage for testing
}

??这似乎不起作用.我究竟做错了什么?谢谢!

解决方法

ASP.Net MVC将自动绑定查询字符串中的参数;你不需要把它放在路线上.

你的路线可以简单

routes.MapRoute(
    "AddLink","Add/Link",action = "Add" }
);

原文地址:https://www.jb51.cc/aspnet/247963.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐