DateTime? problem

Jun 29, 2011 at 3:55 AM
Edited Jun 29, 2011 at 4:04 AM


I have a DateTime? field which I want a DateTimeFor to use.  I have the latest version of the toolkit and when I try this:

@Html.DateTimeFor(model => model.DateFrom, dateInCalendar:true).DateCalendar(inLine: false, calendarOptions: co)

I keep getting a JS error in the MVCControlToolkit.Controls-1.1.5.min.js file.  It is complaining in the DateInputChanged method saying that CurrDate is NULL (which it will be in my case).

I read in another post about the workaround for this but also that you have included it in this toolkit version.  Am I doing somethign wrong with it?

Looking at the code the

var CurrDate=eval(clientID+"_Curr");

returns null since there is no Date value but straight afterwards the CurrDate is used to lookup day etc.



Jun 29, 2011 at 7:36 AM

DateTime input is unable to represent a null value. User has no way to specify a null value, since both the combo boxes or the Calendar always have a date (+ time) selected.

The overload you used doesn't allow to specify an empty date to be used when the supply date is null. This has been fiexed and now all overloads allow to specify an empty date, and if none is supplied DateTime.Now is used. Download the las sources to get this fix (use also the new js file). In a short time I will release the final RTW (just waiting a little for some issue more to be submitted). 

If you want to give the user the option to insert a null date, you must use one of the techniques shown here: