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 に答える