In ASP.NET WebApi: I have a DTO class:
public class DTO
{
public string Date {get; set;}
}
when the client (an Internet Explorer plugin) requests data from this WebApi, I return IEnumerable<DTO>
like this:
return Request.CreateResponse(System.Net.HttpStatusCode.OK, dtoObject)
Where dtoObject
is of type IEnumerable<DTO>
.
While debugging, I check the value of dtoObject[0].Date
and it shows 22-Nov-18 12:00:00 AM
, and this is the expected value.
In the Internet Explorer plugin:
I have a model class called Model
:
public class Model
{
public string Date {get; set;}
}
I request the WebApi Like this:
var response = await httpClient.PostAsJsonAsync(serviceUrl, requestDto);
var returnJson = await response.Content.ReadAsStringAsync();
var result = JsonConvert.DeserializeObject<IEnumerable<Model>>(returnJson)
Now, when I check result[0].Date
I get, 12/11/2018 12:00:00 AM
while I am expecting 22-Nov-18 12:00:00 AM
I have read that date values are serialized differently by different libraries/languages.. But, I am using a string
to store the value then why is the value getting changed? I want to receive the Date
value in dd-MMM-yy hh:mm:ss tt
format. How do I achieve that?