使用查询字符串将 ASP.NET MVC URL 路由到 url
我必须将一个漂亮的 ASP.NET MVC URL '/sel/F/61' 映射到带有查询字符串参数(如 'familydrilldown.aspx?familyid=61')的 ASPX URL。我尝试将其添加到 global.asax:
routeTable.MapPageRoute(
"selectorroute",
"sel/F/{familyid}",
"~/selector/familydrilldown.aspx");
中,该方法有效,只是 familyid 没有作为查询字符串传递给 familydrilldown.aspx。
如何获取 {familyid} 并将其作为查询字符串参数传递给页面 familydrilldown.aspx?
我尝试过这个:
routeTable.MapPageRoute(
"selectorroute",
"sel/F/{familyid}",
"~/selector/familydrilldown.aspx?familyid={familyid}");
但是当然这并没有真正起作用...
关于如何做到这一点有什么想法吗?
谢谢!
I have to map a nice looking ASP.NET MVC URL '/sel/F/61' to an ASPX url with query string parameters like 'familydrilldown.aspx?familyid=61'. I tried to add this to global.asax:
routeTable.MapPageRoute(
"selectorroute",
"sel/F/{familyid}",
"~/selector/familydrilldown.aspx");
which works, except that the familyid is not passed as a querystring to familydrilldown.aspx.
How can I take the {familyid} and pass it as a querystring parameter to the page familydrilldown.aspx?
I tried this:
routeTable.MapPageRoute(
"selectorroute",
"sel/F/{familyid}",
"~/selector/familydrilldown.aspx?familyid={familyid}");
but of course this doesn't really work...
Any ideas on how to do this?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我通过实现自己的 IRouteHandler:
并注册它找到了一个解决方案:
I found a solution by implementing my own IRouteHandler:
and registering it like:
我不知道你想要的是否可以实现。
你为什么不直接使用呢?
在 Page_Load 中(可能涉及一些转换)
I don't know if what you want is possible.
Why don't you just use?
in the Page_Load (there might be some casting involved)