开发者

how to use t4mvc routing helper with custom route constraints

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开发者_JS百科",
               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


Try passing an extra null for the defaults before the constraints. 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()
           }
           );
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜