0

我在当前项目中使用 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陈述An item with the same key has already been added.

如果我这样写

 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 不支持自定义约束

4

1 回答 1

2

尝试在约束之前为默认值传递一个额外的 null。例如

        routes.MapRoute(
           "def_filtered_reports_route",
           "reports/{samplePoint}/{fromDate}/{toDate}",
           MVC.Report.Results(null, null, null),
           null /*defaults*/,
           new {
               samplePoint = new SamplePointExistsConstraint(),
               fromDate = new DateTimeConstraint(),
               toDate = new DateTimeConstraint()
           }
           );
于 2011-08-14T05:51:03.053 回答