Q:

Date format in web api & Ajax application

I have a web api 2 application in which  I have this issue:
in my viewmodel : 
    [DataType(DataType.Date)]
    [DisplayFormat(DataFormatString = "dd/mm/yyyy")]
    [Display(Name = "Date de naissance   ")]
    public Nullable<System.DateTime> birth_date { get; set; }

in the view :
<input type="date" id="editbirth_date" name="birth_date" placeholder="dd/mm/yyyy" />

in the script :
 $.ajax({
                type: "GET",
                url: "/api/Client/GetClient/" + selectedRadio.attr('value'),
                success: function (data) {
                    $('#editid').val(data.id);
                    $('#editcnss').val(data.cnss);
                    $('#editlastname').val(data.lastname);
                    $('#editfirstname').val(data.firstname);
                    $('#editAdresse').val(data.address);
                    $('#editbirth_date').val(data.birth_date);
                    $('#editbirth_place').val(data.birth_place);
                    $('#editmutuelle').val(data.mutuelle);
                    $('#editcaisse_assu_maladie').val(data.caisse_assu_maladie);
                    $('#editclient_type').val(data.client_type);

                    selectView("edit");
                }
            });

and finally, in the controller :
  [HttpGet]
    public ClientModel GetClient(int id)
    {
        ajt_client entity = repo.GetClientById(id);
        ClientModel item = Mapper.Map<ajt_client, ClientModel>(entity);
        return item;
    }

When I debug the code I get 27/02/2015 00:00:00 as a value of item.birth_date.But in the view I get an empty string !!!
I need to know :

Why this happens ?
How can I fix my code?

A:

I think you got this error in the console :
The specified value 'Invalid Date' does not conform to the required format, 'yyyy-MM-dd'.

Indeed, your date is not in the required format, you need to transform it before : 2015-02-27 (instead of 27/02/2015)
The best solution is that your API should return a real Date object and not a formated string. And in the client side, you should be able to parse the real date in the required format yyyy-MM-dd
You can manipulate javascript Dates with this lib : MomentJS
http://momentjs.com/

