在我的全局 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 会自动从查询字符串中绑定(bind)参数;你不需要把它放在路线上。
您的路线可以简单地是
routes.MapRoute(
"AddLink",
"Add/Link",
new { controller = "Link", action = "Add" }
);
关于asp.net-mvc - 如何使用 "?"路由查询字符串以及如何处理它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3596544/