Asp.net mvc 如何将t4mvc布线辅助程序与自定义布线约束一起使用

Asp.net mvc 如何将t4mvc布线辅助程序与自定义布线约束一起使用,asp.net-mvc,asp.net-mvc-3,t4mvc,Asp.net Mvc,Asp.net Mvc 3,T4mvc,我在当前项目中使用t4mvc,并尝试使用包含的路由帮助器,但当我尝试使用自定义约束时,如下所示 routes.MapRoute( "def_filtered_reports_route", "reports/{samplePoint}/{fromDate}/{toDate}", MVC.Report.Results(null, null, null), new { samplePoi

我在当前项目中使用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()
           });
还是像这样

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

请尝试在约束之前为默认值传递一个额外的null。e、 g

        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()
           }
           );

如果我使用帮助器,我还需要在匿名对象中使用默认值定义控制器和操作吗?或者如果操作被删除,我的帮助器是否仅设计为中断?如果使用帮助器,则传递MVC.Report.Results(…)确实消除了在默认匿名对象中传递控制器/操作的需要。因此,只需将默认值传递给帮助器,并以默认方式抛出空值,听起来不错,谢谢david