加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

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

发布时间:2020-12-16 04:20:20 所属栏目:asp.Net 来源:网络整理
导读:在我的全局asax文件中,我想映射一个这样的路由: http://domain.com/add/link?url=http%3A%2F%2Fgoogle.com 然后使用我的LinkController和名为Add的操作捕获它. 我这样做吗? global.asax- routes.MapRoute( "AddLink","Add/Link?{url}",new { controller =
在我的全局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" }
);

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读