Question

How do you clear the datebox value? On load my datebox has the following data by default: "01/01/0001 00:00:00"

From View:

@Html.TextBoxFor(m => m.Date, new { @id = "date", @name = "date", @data_role =     "datebox",@value="", @data_options = " {'mode':'calbox' }", @onload="this.value='';" })

From Controller:

Was it helpful?

Solution

if you want to have an empty string in the textbox if the value is not given yet then you have to use Nullable DateTime in the Model:

class Model {
  public DateTime? Date { get;set; }
}

The call in the view remains the same:

@Html.TextBoxFor(m => m.Date)

OTHER TIPS

You can use jQuery for that:

$(function(){
  $("#date").text("");
});

u can use

     $(document).ready(function(){
       $("#Date").val("");
     });

Note: better if u set the datetime value to current datetime in ur model, or else make it nullable and set it to null (or dont set it)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top