Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

332
Views
How show Empty string in Textbox when Date is NULL

I have a DateTime as this is C#:

public DateTime ShipmentDate { get; set; }

I show the value in textbox

This is in cshml:

        <div class="col-sm-2">
            <label for="ShipmentDate">Shipment Date:</label><br />
            <input type="text" name="ShipmentDate" id="ShipmentDate" disabled="disabled" />
        </div>

And this is in JavaScript:

   $('#ShipmentDate').val($.formatDate(PurchaseOrder.ShipmentDate));

When ShipmentDate is nullable like this:

 public DateTime? ShipmentDate { get; set; }

and the date is empty, it shows some random Date as 1960/12/31 in textbox

When ShipmentDate is not nullable shows the date as: 1/1/0001 in textbox

In both in C# date is Null and when I do console.log shows null in the console. How I can show empty String in textbox when ShipmentDate in Null.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Since PurchaseOrder.ShipmentDate can be null, it is worth handling this case so that the $.formatDate(null) doesn't return an invalid date as noticed.

In Javascript, if a variable is null then is treated as a falsy value. So it only executes the formatDate if the ship is not one of the many falsy values, including null.

const ship = PurchaseOrder.ShipmentDate;
$('#ShipmentDate').val(ship ? $.formatDate(ship) : "");
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!