title: How do i have optional parameter but still validate them in asp.net mvc routing?
body: <p>I have this route that i just added</p>
  
  <pre><code>        routes.MapRoute(
              "MyRoute",
              "MyController/{action}/{orgId}/{startDate}/{endDate}",
              new
                  {
                      controller = "MyController",
                      action = "MyAction",
                      orgId = 0,
                      startDate = DateTime.Today.AddMonths(-1),
                      endDate = DateTime.Today
                  },
              new
              {
                  action = new FromValuesListConstraint(new string[] { "MyAction", "MyActionEx" }),
                  orgId = new IntegerRouteConstraint(),
                  startDate = new DateTimeRouteConstraint(),
                  endDate = new DateTimeRouteConstraint()
              }
  </code></pre>
  
  <p>when i put in this url, it resolves down to the default route (controller, action,id) and the above rout does not catch this url:</p>
  
  <pre><code>http://localhost:1713/MyController/MyAction/16
  </code></pre>
  
  <p>But this below works fine.  </p>
  
  <pre><code>http://localhost:1713/MyController/MyAction/16/11-May-10/11-May-10
  </code></pre>
  
  <p>my question is that i thought both would work as i am giving default values to the startDate and enddate fields</p>
  
  <p>i tested this using <a href="http://haacked.com/archive/2008/03/13/url-routing-debugger.aspx" rel="nofollow">the RouteDebugger</a> and this route turned up false</p>
  
  <p>how can i have these last two parameter as optional but still have the validation ?</p>