So i have made a datepicker that keeps the date that some have change it to, but the problem is that i dont like that it starts with 01.01.0001 when you get on that page.
Like this: https://imgur.com/a/rOYTqra
This is my datepicker code:
<form method="post" asp-page-handler="TestClick">
<br />
<br />
<input asp-for="Date" />
<button>Search</button>
<br />
</form>
from my .cshtml file
[BindProperty, DataType(DataType.Date)]
public DateTime Date { get; set; }
public void OnPostTestClick()
{
String testDate = Request.Form["Date"];
Debug.WriteLine("Testclick verdi2 = " testDate);
filterdato = testDate;
ListData();
}
from my .cshtml.cs file.
I was wondering if there was a way for me to still have the function of keeping the dates when someone changes it in the datepicker, but also have the datepicker start with "dd.mm.yyyy" once you enter the page?
CodePudding user response:
The default value of DateTime
is 01.01.0001
. Make your DateTime
property nullable (DateTime?
) so that default value is null
:
public DateTime? Date { get; set; }