Search code examples
asp.net-mvcasp.net-mvc-3razorglobalization

override date format in mvc 3 with globalization set


I have a mvc website using razor where the globalization is set to auto and it is using the clients preferred culture.

<globalization requestEncoding="utf-8" responseEncoding="utf-8" culture="auto" uiCulture="auto" enableClientBasedCulture="true" />

What I'd like to know is there a way to force a date that is being bound via razor to show in a specific format ignoring the culture?

For example if I have a model

public class someObj
{
  public DateTime someDateTime { get; set; }
}

And I bind it like so in the view:

@Model.someDateTime

Can I override the preferred culture that the browser wants?

Thanks in advance.


Solution

  • Call @Model.SomeDate.ToString("Some Format", new CultureInfo(...))