I\'m trying to get cultural specific data annotations.
[DisplayFormat(DataFormatString = \"{0:d}\")]
public DateTime Date{ get; set; }
I though
This format is culture specific. You must be doing something wrong.
Add a view model:
public class MyViewModel
{
[DisplayFormat(DataFormatString = "{0:d}")]
public DateTime Date { get; set; }
}
A controller:
public class HomeController : Controller
{
public ActionResult Index()
{
return View(new MyViewModel
{
Date = DateTime.Now,
});
}
}
And a view:
@using MvcApplication1.Models
@model MyViewModel
@Html.DisplayFor(x => x.Date)
Now force the culture in your web.config to some specific culture:
...
So make sure you set the culture to auto in this case:
...
Then the browser will send the proper Accept-Language
request header that looks like this:
and obviously the result will be formatted as expected: