I am posting data to my web api, one of the parameters I am posting is a date selecteed by a date picker.
Below is the post data to the action (got these values from firebug)
EndDate : "18/10/2012" (Note: the format is : dd/mm/yyyy)
ABC : "do not bother…"
XYZ : "do not bother…"
LMNO : "do not bother…"
Now in my controller I have a class with the above 3 string fields and one date field
public class PostModel{
public string ABC {get;set;}
public string XYZ {get;set;}
public string LMNO {get;set;}
public DateTime EndDate {get;set;}
}
in my web api which looks somewhat like the one shown below
public Something PostSomething(PostModel model)
{}
here I am getting the value of EndDate in the format of "mm/dd/yyyy". What I want is "dd/mm/yyyy".
So for this I have also added a entry in the web.config file as follows…
<system.web>
<globalization uiCulture="en-GB" culture="en-GB" />
</system.web>
This still doesnt help, please can someone tell me what wrong I am doing ?
MORE SHOCKING DISCOVERY !!!
I just tried this out with a normal controller instead of web api controller and it worked for the non – api controller. Has any body else come across this problem ??
For the normal action (non web api) I didnt even had to set any culture for this.
please help.
Changed my End Date date time field to string and then posted this end date as string to my controller.
Then in controller converted this string to date using
DateTime.Parse().I know that this not the best solution one would want, but this gets the job done.