1
votes

I have the below fields in UI

  • Appointment Date 04/13/2013
  • Start Time 13:00
  • End Time 14:30

The current database design is

  • AppointmentDate SMALLDATETIME Ex value 04-13-2013
  • Start Time SMALLDATETIME Ex value 04-13-2013 13:00
  • EndTime SMALLDATETIME Ex value 04-13-2013 14:30

I designed a class for this model

public class Appointment
{
DateTime? AppointmentDate{get;set;}
DateTime? StartTime{get;set;}
DateTime? EndTime{get;set;}

}

I use ASP.Net MVC 4 and

 @Html.TextBox("", m.StartTime.ToString("HH:mm"))

Added jQuery validation plugin and i get validation message 14:30 is not a valid date.

What changes i can implement in UI/DataBase/Validation to handle time entry?

I am using SQL Server 2008

2

2 Answers

1
votes

Your start time and end time properties need to be decimals in the view model, as that is what you are passing back from the view on post.

1
votes

Have you tried explicitly setting the datatype of the columns:

public class Appointment
{
    [DataType(DataType.Date)]
    public DateTime? AppointmentDate { get; set; }

    [DataType(DataType.Time)]
    public DateTime? StartTime { get; set; }

    [DataType(DataType.Time)]
    public DateTime? EndTime { get; set; }
}