如何将 t4mvc 路由助手与自定义路由约束一起使用
我在当前项目中使用 t4mvc 并尝试使用包含的路由助手,但是当我尝试使用如下所示的自定义约束时,
routes.MapRoute(
"def_filtered_reports_route",
"reports/{samplePoint}/{fromDate}/{toDate}",
MVC.Report.Results(null, null, null),
new
{
samplePoint = new SamplePointExistsConstraint(),
fromDate = new DateTimeConstraint(),
toDate = new DateTimeConstraint()
}
);
它会抛出一个 ArgumentException
,说明 具有相同键的项目已经添加。
如果我这样写
routes.MapRoute(
"def_filtered_reports_route",
"reports/{samplePoint}/{fromDate}/{toDate}",
MVC.Report.Results(null, null, null) );
或这样
routes.MapRoute(
"def_filtered_reports_route",
"reports/{samplePoint}/{fromDate}/{toDate}",
new
{
controller = "Report",
action = "Results",
fromDate = "",
toDate = "",
samplePoint = ""
},
new
{
fromDate = new DateTimeConstraint(),
toDate = new DateTimeConstraint(),
samplePoint = new SamplePointExistsConstraint()
});
写它就可以正常工作。
有什么我遗漏的或者 t4mvc 不支持自定义约束吗
im using t4mvc in my current project and am trying to use the routing helper included however when i try to use custom constraints as below
routes.MapRoute(
"def_filtered_reports_route",
"reports/{samplePoint}/{fromDate}/{toDate}",
MVC.Report.Results(null, null, null),
new
{
samplePoint = new SamplePointExistsConstraint(),
fromDate = new DateTimeConstraint(),
toDate = new DateTimeConstraint()
}
);
it throws an ArgumentException
stating An item with the same key has already been added.
if i write it like this
routes.MapRoute(
"def_filtered_reports_route",
"reports/{samplePoint}/{fromDate}/{toDate}",
MVC.Report.Results(null, null, null) );
or like this
routes.MapRoute(
"def_filtered_reports_route",
"reports/{samplePoint}/{fromDate}/{toDate}",
new
{
controller = "Report",
action = "Results",
fromDate = "",
toDate = "",
samplePoint = ""
},
new
{
fromDate = new DateTimeConstraint(),
toDate = new DateTimeConstraint(),
samplePoint = new SamplePointExistsConstraint()
});
it works fine.
Is there something I'm missing or does t4mvc not support custom constraints
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试在约束之前为默认值传递一个额外的空值。例如
Try passing an extra null for the defaults before the constraints. e.g.