如何在给定虚拟路径的情况下创建 RouteValueDictionary
我想知道是否有一种方法,在给定虚拟路径的情况下,将返回与该路径匹配的路由的参数名称和值的集合。我需要它来获取目标页面上 URL 的参数,而不需要硬编码正则表达式。
我猜这与 RouteTable.Routes.GetVirtualPath 相反,它采用 RouteValueDictionary 并返回虚拟路径。
这可能吗?
标记
I would like to know if there is a method that, given a virtual path, will return a collection of parameter names and values for a route that matches the path. I need this to get the parameters of the URL on the target page without resorting to hard-coding a regular expression.
This is I guess the reverse of RouteTable.Routes.GetVirtualPath that takes a RouteValueDictionary and returns a virtual path.
Is this possible?
Mark
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看看我的类似问题及其答案: RouteValueDictionary 的字符串 URL
编辑
Piotr Czapla 提供了不需要模拟库的解决方案。看看您是否还有兴趣解决这个问题
Take a look at my similar question and answers to it: String URL to RouteValueDictionary
Edit
Piotr Czapla had provided solution that does not require mocking library. Take a look if you are still interested in solving this problem