C# 运行应用程序时未显示开始和结束时间
在线运行代码时,填充表时遇到一些问题。我在DbInitializer中创建的约会日期会出现,但开始时间和结束时间不会在线显示 我想这和我的预约有关。如果有人能帮忙,我将不胜感激 这是任命控制器的索引部分C# 运行应用程序时未显示开始和结束时间,c#,asp.net,visual-studio,C#,Asp.net,Visual Studio,在线运行代码时,填充表时遇到一些问题。我在DbInitializer中创建的约会日期会出现,但开始时间和结束时间不会在线显示 我想这和我的预约有关。如果有人能帮忙,我将不胜感激 这是任命控制器的索引部分 public async Task<IActionResult> Index(string sortOrder) { ViewData["DateSortParm"] = sortOrder == "Date" ? "date_desc" : "Date";
public async Task<IActionResult> Index(string sortOrder)
{
ViewData["DateSortParm"] = sortOrder == "Date" ? "date_desc" : "Date";
var appointments = from s in _context.Appointments.Include(a => a.Customer).Include(a => a.Staff)
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());
}
更新
这是DbInitializer中的代码
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();
}
这是约会部分的屏幕截图。我已经填充了数据库,以显示开始和结束时间,但正如您所看到的,没有任何东西能够通过
问题可能出在UI绑定部分?首先将结果放入临时列表变量中。观察您的查询结果。项目是否具有具有预期值的此列?。如果为true,则问题在于mvc格式化数据。如果为false,请使用SQL profiler查看针对数据库的EF查询(EF select查询是否包含预期列),我猜这与我的mvc格式有关,因为我可以在SQL资源管理器中查看所有数据。当我去创建一个新的约会时,约会日期起作用,但是开始和结束时间仍然没有通过我给他们的值。这有什么问题吗?我已经看过UI绑定,我觉得这一切都是正确的。也许问题出在UI绑定部分?首先将结果放入临时列表变量中。观察您的查询结果。项目是否具有具有预期值的此列?。如果为true,则问题在于mvc格式化数据。如果为false,请使用SQL profiler查看针对数据库的EF查询(EF select查询是否包含预期列),我猜这与我的mvc格式有关,因为我可以在SQL资源管理器中查看所有数据。当我去创建一个新的约会时,约会日期起作用,但是开始和结束时间仍然没有通过我给他们的值。这有什么问题吗?我已经看过UI绑定,我觉得这一切都是正确的。
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();
}