Razor language regionality

Asked

Viewed 100 times

0

I’m having a problem with Razor (using MVC 2.1 .Net Core) when generating the screen, as follows code below, this appearing the correct date in my Local development environment, but after Publish appears in English in other environments, would be forced 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.

  • Configure the Culture of an olhda here https://answall.com/questions/137931/como-usar-recursos-portugu%C3%Aas-br-de-microsoft-Asp-net-mvc

  • I looked at the post, but in my case there is no web.config, as it is Dotnetcore 2.1.

  • You could post your model?

  • look at the @Barbetta response via code

2 answers

2


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

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

This way to use just call the @Model.DataEmissaoAntecedentes.Value, the format you can edit on DataFormatString

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

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

0

Worked!

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

Just add as our friend Barbetta, reported! Thank you.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.