I have a problem sending a date in the format DD/MM/YY. This all works fine if I use the YY/MM/DD format, but my application is specific to the UK so I wish to only support this format.
My controller method begins like this:
public IActionResult Index(DateTime startDate, DateTime endDate)
and the problem is that both date values are just coming in 0001-01-01 (DateTime.MinValue)
The controls are created in the .cshtml using the below.
@Html.TextBox("startDate", "", new { @class = "form-control datepicker", @placeholder = "dd/mm/yy" })
and this is wired up to a jQuery UI DatePicker. However I do not believe this is related to the issue as I said before, it works if I change to YY/MM/DD.
From findings on other questions on StackOverflow I have tried adding the following, but the issue still persists.
Startup.cs:
ConfigureServices Method:
services.Configure<RequestLocalizationOptions>(options =>
{
options.DefaultRequestCulture = new RequestCulture("en-GB");
options.SupportedCultures = new List<CultureInfo> { new CultureInfo("en-GB") };
options.RequestCultureProviders.Clear();
});
Configure Method:
app.UseRequestLocalization(new RequestLocalizationOptions
{
DefaultRequestCulture = new RequestCulture("en-GB"),
SupportedCultures = supportedCultures,
SupportedUICultures = supportedCultures
});
I can confirm both of these are done before calling .AddMvc() / .UseMvc() as this was mentioned on another question.
I am a bit of a loss now, any ideas would be greatly appreciated.