Link to home
Start Free TrialLog in
Avatar of Stacey Fontenot
Stacey Fontenot

asked on

Check for date value in input field, else return default date

I have an MVC C# Application. On the cshtml page, i have a date input field. Sometimes the user leaves it blank and sometimes fills it in. I need to evaluate whether the field is blank or not in the controller. If it is blank, I would like to insert a default value of '01/02/1901'. I'm using html 5.

input code is below:
<input type="date" name="Date Worked" id="add_Date_Worked" class="form-control" required />

Open in new window

Avatar of Pratik Somaiya
Pratik Somaiya
Flag of India image

You can try the following:

public class Employee
  {
      private employeeJoinDate = DateTime.Now; /*Here DateTime.Now will send the current date, you can hard code it as well*/
      public DateTime EmployeeJoinDate
      {
        get
          {
              return employeeJoinDate;
          }
          set
          {
              employeeJoinDate= value;
          }
      }
}

Open in new window


Regards,
Pratik
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.