0

I have a route like

        routes.MapRoute(
        "Reports",                                              // Route name.
        "reports/{controller}/{action}/{id}/{start}/{end}",     // URL with parameters.
        new { controller = "Home", action = "Index", id = "", start="", end="" }  // Parameter defaults.
    );

where start and end are DateTime?

When I write an Html.ActionLink, it generates the route using the DateTime.ToString method. Those dates have forward slashes in them which disrupts the route. I'd like to somehow control the route generation to generate ISO 8601 date strings.

Ideally I don't want to have to change my Actions to take strings and convert in my code, I'd like to signal the route generator to call the appropriate ToString overload of my choice.

1 Answer 1

4

In your Html.ActionLink, when you're declaring the start and end values, why not do something like:

new{start = String.Format("{0:YYYY-MM-dd}", SomeDate)}

or this if you need the time in there too:

new{start = String.Format("{0:s}", SomeDate)}

Bit of work, but it will guarentee it's formatted correctly.

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

1 Comment

You mean yyyy-MM-dd (lower-case for year)?

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.