2

I have created a new route like the following:

   routes.MapRoute(
     "BlogYMD",
     "blog/date/{year}/{month}/{day}",
     new { controller = "Blog", action = "Date", year = "2009", month="01", day="01" });

The view simply returns a concatenation of year, month and day. This works fine for URL's like:

http://localhost/blog/date/2009/01/01

However if I enter this URL:

http://localhost/blog/date/2009

I would expect the default values for month and day to be passed to the date method. However they aren't, all the parameters on the method come through as null.

Am I missing something obvious?

1
  • How are they coming through as null, you should have the parameters as integers, the binding system in mvc will take of casting them. Commented Apr 13, 2009 at 12:47

2 Answers 2

2

You don't show the rest of your routes, but I suspect you have another route above this one in your global.asax.CS (for example, the default route) which matches the second URL.

Sign up to request clarification or add additional context in comments.

Comments

2

The order in which you declare routes is important. You want your custom route(s) declared before the default.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.