0

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

Chris McGrath
  • 1,727
  • 3
  • 19
  • 45

1 Answers1

2

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()
           }
           );
David Ebbo
  • 42,443
  • 8
  • 103
  • 117
  • if im using the helper do i still need to define controller and action in the anonymous object with the default values or is the Helper only designed to break if the action is deleted – Chris McGrath Aug 15 '11 at 14:33
  • If you use the helper, then passing MVC.Report.Results(...) does indeed remove the need to pass the controller/action in the default anonymous object. – David Ebbo Aug 15 '11 at 20:45
  • so just pass your defaults with the helper and just toss a null to the default way then sounds good thanks david – Chris McGrath Aug 17 '11 at 14:38