在线运行代码时填充表格时遇到一些问题。我在DbInitializer中创建的约会日期出现,但StartTime和EndTime未在线显示。
我认为这与我的约会控制器有关。如果有人能提供帮助,那将非常感激。
这是AppointmentController的索引部分
{
public class Appointment
{
public int AppointmentID { get; set; }
public int CustomerID { get; set; }
public int StaffID { get; set; }
//[DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)]
//[Display(Name = "Appointment Date")]
[DataType(DataType.Date)]
[DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)]
[Display(Name = "Appointment Date")]
public DateTime AppointmentDate { get; set; }
[DataType(DataType.Time)]
[DisplayFormat(DataFormatString = "{00:00:00}", ApplyFormatInEditMode = true)]
[Display(Name = "End Time")]
public DateTime EndTime { get; set; }
[DataType(DataType.Time)]
[DisplayFormat(DataFormatString = "{00:00:00}", ApplyFormatInEditMode = true)]
[Display(Name = "Start Time")]
public DateTime StartTime { get; set; }
public Customer Customer { get; set; }
public Staff Staff { get; set; }
}
}
select s;
switch (sortOrder)
{
case "Date":
appointments = appointments.OrderBy(s => s.AppointmentDate);
break;
case "date_desc":
appointments = appointments.OrderByDescending(s => s.AppointmentDate);
break;
default:
appointments = appointments.OrderBy(s => s.AppointmentDate);
break;
}
return View(await appointments.AsNoTracking().ToListAsync());
}
这是约会的模型
var appointments = new Appointment[]
{
new Appointment{CustomerID=1,StaffID=1,AppointmentDate=DateTime.Parse("20/07/2017"),StartTime=DateTime.Parse("16:00:00"),EndTime=DateTime.Parse("17:00:00")},
new Appointment{CustomerID=2,StaffID=2,AppointmentDate=DateTime.Parse("20/05/2017"),StartTime=DateTime.Parse("17:00:00"),EndTime=DateTime.Parse("17:00:00")},
new Appointment{CustomerID=3,StaffID=3,AppointmentDate=DateTime.Parse("20/04/2017"),StartTime=DateTime.Parse("17:00:00"),EndTime=DateTime.Parse("17:00:00")},
new Appointment{CustomerID=4,StaffID=4,AppointmentDate=DateTime.Parse("20/03/2017"),StartTime=DateTime.Parse("17:00:00"),EndTime=DateTime.Parse("17:00:00")},
new Appointment{CustomerID=5,StaffID=5,AppointmentDate=DateTime.Parse("20/02/2017"),StartTime=DateTime.Parse("17:00:00"),EndTime=DateTime.Parse("17:00:00")},
new Appointment{CustomerID=6,StaffID=6,AppointmentDate=DateTime.Parse("20/09/2017"),StartTime=DateTime.Parse("17:00:00"),EndTime=DateTime.Parse("17:00:00")},
new Appointment{CustomerID=7,StaffID=7,AppointmentDate=DateTime.Parse("20/08/2017"),StartTime=DateTime.Parse("17:00:00"),EndTime=DateTime.Parse("17:00:00")},
new Appointment{CustomerID=8,StaffID=8,AppointmentDate=DateTime.Parse("20/06/2017"),StartTime=DateTime.Parse("17:00:00"),EndTime=DateTime.Parse("17:00:00")}
};
foreach (Appointment c in appointments)
{
context.Appointments.Add(c);
}
context.SaveChanges();
}
更新 这是我的DbInitializer中的代码
{"id":"45961","title":"Independien - Sporting Cri","type":"1","flag":"tr","date":"2017-03-17 03:45:00","date":"03\/17\/2017 04:32:55","live":"1"},{"id":"45962","title":"Independien - Sporting Cri","type":"1","flag":"tr","date":"2017-03-17 03:45:00","date":"03\/17\/2017 04:32:55","live":"1"}
这是约会部分的屏幕截图。我已经填充了数据库以显示开始和结束时间,但是你可以看到没有任何东西被拉过来。