locked
Link creation with dates RRS feed

  • Question

  • User-722752682 posted

    Within a Json response I am returning a link to a URL using UrlHelper as follows:

    Url.Link("DefaultApi", new { controller = "MyController", time = model.Time } )

    This is creating a query string parameter for "time" in the URL, as I was expecting, but it is formatted as (what I would call) a U.S. date (month, day, year, hour, minute, second). I think this is due to the conversion of a DateTime in the invariant culture producing a U.S. formatted date (which is odd in itself), but I would much prefer if the date were formatted according to ISO 8601.

    I can do this conversion manually, in each controller, but I am looking for an extension point that will do this for all query string parameters of type DateTime. Searching around I can't see that any of the many Web API extension points allow control over the formatting of query string parameters.

    Is there a way to do this?

    Thanks.

    Thursday, March 5, 2015 7:51 AM

Answers

  • User103933760 posted

    Hi,

    I am looking for an extension point that will do this for all query string parameters of type DateTime. Searching around I can't see that any of the many Web API extension points allow control over the formatting of query string parameters.

    For this situation, I am not sure whether there is such a way to achieve this.

    But you could define a global variable and change the variable format into what you want. Then using it within others' controllers.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, March 6, 2015 6:12 AM

All replies

  • User103933760 posted

    Hi,

    I am looking for an extension point that will do this for all query string parameters of type DateTime. Searching around I can't see that any of the many Web API extension points allow control over the formatting of query string parameters.

    For this situation, I am not sure whether there is such a way to achieve this.

    But you could define a global variable and change the variable format into what you want. Then using it within others' controllers.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, March 6, 2015 6:12 AM
  • User-722752682 posted

    Ok thanks.

    The lack of any other answers would appear to mean that you are indeed correct!

    Saturday, April 25, 2015 2:26 PM