How do i have optional parameter but still validate them in asp.net mvc routing ?
- by ooo
I have this route that i just added
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()
}
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:
http://localhost:1713/MyController/MyAction/16
But this below works fine.
http://localhost:1713/MyController/MyAction/16/11-May-10/11-May-10
my question is that i thought both would work as i am giving default values to the startDate and enddate fields
i tested this using the RouteDebugger and this route turned up false
how can i have these last two parameter as optional but still have the validation ?