Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

326
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda