taia
taia

Reputation: 61

How do you clear the datebox value?

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:

Upvotes: -3

Views: 747

Answers (3)

Developer
Developer

Reputation: 769

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)

Upvotes: 0

Nathalie Kellenberger
Nathalie Kellenberger

Reputation: 341

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)

Upvotes: 2

Kapil Khandelwal
Kapil Khandelwal

Reputation: 16144

You can use jQuery for that:

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

Upvotes: 1

Related Questions