I'm working in an MVC application. I would like my date to be always in the format dd/MM/yyyy
for example 16/04/2017
.
Here's a scenario from my application. I have a SaleOrder.cs
entity, I have a public DateTime Date { get; set; }
property. When viewing the details of the SaleOrder, I'd like the date to show as 16 Apr 2017
and when editing a SaleOrder, I'd like the input to be populated in the following format 16/04/2017
.
This isn't happening for me at the moment. I've captured the current behaviour in the following screencast.
My EditorTemplate for DateTime
is like so:
@model DateTime
@{
IDictionary<string, object> htmlAttributes;
object objAttributes;
if (ViewData.TryGetValue("htmlAttributes", out objAttributes))
{
htmlAttributes = objAttributes as IDictionary<string, object> ?? HtmlHelper.AnonymousObjectToHtmlAttributes(objAttributes);
}
else
{
htmlAttributes = new RouteValueDictionary();
}
htmlAttributes.Add("type", "date");
var format = (Request.UserAgent != null && Request.UserAgent.Contains("Chrome")) ? "{0:dd/MM/yyyy}" : "{0:d}";
@Html.TextBox("", Model, format, htmlAttributes)
}
How can I get my DateTime values to behave?