-2
I developed the system in layers, and I have 2 layers, where layer number 1 is my API and number 2 is where I keep my classes.
In one of the classes I have a field of type DateTime
.
I created a method in my API that takes an object from this class.
I’m in charge of Postman, um request with the date attribute value of that object equal to 01/07/2018
But when the request hits the API the same attribute comes with the value 07/01/2018
As demonstrated below
[HttpPost]
[Route("Salvar")]
public HttpResponseMessage Post(IntencaoDeCompraViewModel obj)
{
ApiResult result = _intencaoDeCompraJsonAppServices.AddLead(obj);
if (result.Status == MessageType.Error)
return Request.CreateResponse(HttpStatusCode.BadRequest, result);
return Request.CreateResponse(HttpStatusCode.OK, result);
}
Include your controller code and the section where you are assigning this input value and the conversion is being done. What is the version of mvc and . net framework?
– Leandro Angelo
I entered the controller code. The MVC version is 5 and the . NET version is 4.6.1
– Guilherme Nunes
tried to put the
<globalization culture="pt-BR" uiCulture="pt-BR" />
on web.config? and or declare the format in Viewmodel?– Leandro Angelo
Sim, olha como está: <globalization enableClientBasedCulture="false" requestEncoding="utf-8" responseEncoding="utf-8" fileEncoding="iso-8859-1" responseHeaderEncoding="utf-8" resourceProviderFactoryType="string" enableBestFitResponseEncoding="true" culture="pt-BR" uiCulture="pt-BR" />
– Guilherme Nunes
I couldn’t reproduce this behavior here... even changing the language the mvc didn’t change the date format
– Leandro Angelo
Is the problem in Postman?
– Guilherme Nunes
I did it for Postman too, see if you don’t have any other settings in global.asax.Cs
– Leandro Angelo
Strange! I don’t know then rs
– Guilherme Nunes
No global.asax ta normal tbm, I have nothing more rs. The test you did was layered or used the same layer class?
– Guilherme Nunes
Let’s go continue this discussion in chat.
– Leandro Angelo
@Guilhermenunes You’ll need to configure the serializer to work with dates in the application culture. You use the standard Webapi 2 serializer?
– Jéf Bueno
I don’t know, to tell you the truth, I don’t know
– Guilherme Nunes