Home > Net >  How to create a Calendar date/picker in ASP.net Core?
How to create a Calendar date/picker in ASP.net Core?

Time:12-21

enter image description here

My goal is to have a date/picker calendar that will DL a log on the chosen date when the Download Log button is clicked. So far, I have a code that just DLs the todays date. How will manage to control the the date/picker and chose a date and DLs that chosen date with the (Download Log Button)? Thank you..

enter image description here

CodePudding user response:

As stated in my comment, change your Method to accept the Date as a parameter:

[HttpPost]  
public ActionResult Download(DateTime? downloaddate)

Add name attribute to your input so that it matches the method parameter name

<input type="date" id="myDate" name="downloaddate" style="..."

Now when you submit the form, you should get a value in your method if the user selected a date. This does accept a null value as the date in the backend method in case the user submits without choosing a date , so you will need to handle this server side. The DateTime? is a nullable DateTime

  • Related