Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Chris Smith 4 posts 51 karma points
    Sep 03, 2014 @ 23:58
    Chris Smith
    0

    Umbraco API Controller and UK Date format

    Hi,
    I have created an api controller using the following guide
    http://our.umbraco.org/documentation/Reference/WebApi/

    In this controller is a methd called PostHoliday(HolidayModel item)
    and the model has a start date and end date properties both of type DateTime

    When I call it from jquery the date is always converted to US format. Therefore if after 12th of the month then the date is invalid and comes in as 01/01/0001

    In another project outside of Umbraco I used IModelBinder and registered this in the global.asax.

    IModelBinder dateBinder = new DateTimeModelBinder();
    ModelBinders.Binders.Add(typeof(DateTime), dateBinder);
    ModelBinders.Binders.Add(typeof(DateTime?), dateBinder);

    Tried registering the same thing in ApplicationEventHandler but this doesn't work

    How can I get Umbraco API Controller to use UK date formats when model binding?

    Thanks

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Sep 04, 2014 @ 12:18
    Jeroen Breuer
    0

    Hello,

    I've had the same problem. I posted the culture as a parameter to the WebAPI and then do this:

    //Set the culture which is passed from the ajax call.
    System.Globalization.CultureInfo ci = new System.Globalization.CultureInfo(culture);
    System.Threading.Thread.CurrentThread.CurrentCulture = ci;
    System.Threading.Thread.CurrentThread.CurrentUICulture = ci;

    Jeroen

Please Sign in or register to post replies

Write your reply to:

Draft