Razor language regionality

0

I'm having a problem with Razor (using MVC 2.1 .Net Core) when generating the screen, as below code, it is appearing the correct date in my Local development environment, but after Publish appears in English in other environments, could you force it to be in Portuguese?

<p>       <label> Data de Nascimento:</label>}
           @Model.DataEmissaoAntecedentes.Value.ToLongDateString()
</p>

The page is in CSHTML, and is typed with a Model.

    
asked by anonymous 09.10.2018 / 20:36

2 answers

2

An alternative is to use the Annotation DisplayFormat , below an example:

public class Modelo
{
    [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:dd/MM/yyyy}")]
    public DateTime? DataEmissaoAntecedentes{ get; set; }
}

In this way to use just call @Model.DataEmissaoAntecedentes.Value , the format you can edit in DataFormatString

Another alternative is to change the application culture, within Startup in the Configure method, add the following code:

var cultureInfo = new CultureInfo("pt-BR");
CultureInfo.DefaultThreadCurrentCulture = cultureInfo;
    
09.10.2018 / 20:49
0

It worked!

 var cultureInfo = new CultureInfo("pt-BR");
 CultureInfo.DefaultThreadCurrentCulture = cultureInfo;

Just added as our Friend Barbetta, reported! Thank you.

    
09.10.2018 / 21:44