ASP.NET MVC 是否有任何 DateTime 路由约束?
ASP.NET MVC 是否包含任何嵌入到代码中的路由约束?如果是这样,我如何定义日期时间约束?
例如。网址:
http://mydomain.com/{versionDate}/{controller}/{action}
http://mydomain.com/2010-01-20/search/posts
干杯:)
does ASP.NET MVC contain any route contraints baked into the code? if so, how do i define a date-time constraint?
eg. url:
http://mydomain.com/{versionDate}/{controller}/{action}
http://mydomain.com/2010-01-20/search/posts
cheers :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我最终制定了自己的路线限制。只花了几分钟。
简单:P
I ended up making my own route constraint. only took a few mins.
simple :P
您还可以对路线设置约束,类似这样。使用的正则表达式不是很健壮,因此您应该对其进行改进。
信息来自此处。
You could also set up a constraint on the route, something like so. The regular expression used is not very robust, so you should refine it.
Information from here.
所有框架都是可覆盖的,因此有可能覆盖路由引擎的默认行为,但要付出很大的痛苦,但我同意@jrista,因为你可能希望将其作为控制器的参数,否则 mvc 会期望在 2010-01-20 文件夹中找到 /search/posts
all of the framework is overide-able so it's possible, with a great deal of pain, to overide the default behaviour of the route engine but i agree with @jrista in that you might want to make it a parameter of the controller else mvc will expect to find /search/posts within the 2010-01-20 folder