Just start doing MVC. Following the example in this page: Adding Validation in this Getting Started with ASP.NET MVC 5 tutorial.
In the model, there is a date and format as:
using System;
using System.ComponentModel.DataAnnotations;
namespace MvcMovie.Models
{
public class Movie
{
public int ID { get; set; }
public string Title { get; set; }
[Display(Name = "Release Date")]
[DataType(DataType.Date)]
[DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)]
public DateTime ReleaseDate { get; set; }
public string Genre { get; set; }
public decimal Price { get; set; }
}
}
The date format is according to this SO Answer. So (using Chorme, Edge and IE) when I in the i) Index page, ii) Details page, or even in the iii) Delete page, I see the date displayed as yyyy-MM-dd (e.g. 1959-04-15 for April 15 in 1959).
But when I go to Edit page, the date is different for different browser.
Chrome: 04/15/1959
Edge: 4/15/1959
IE: 1959-04-15
(When I view source in all 3 browsers, all show 1959-04-15.)
I think the following suggestion (according to the tutorial's description is causing the trouble, but even I remove the following culture specification, the result for all browsers are same.
<system.web>
<globalization culture ="en-US" />
<!--elements removed for clarity-->
</system.web>
- The regional setting in my computer is 'English (Hong Kong SAR)'. Short date is format as d/M/yyyy.
- Also when i view data in the Local DB, the date shown is '15/4/1959 0:00:00'. Looks like it uses the computer's regional setting.
Can anyone explain why the date is different in Edit mode? Also how to fix for Chrome? I know someone has suggested other methods (like adding a model, file, etc), but I just want to see if there is an easy solution without adding additional file/model. Thanks.