我有两个模型,SelectDate
和Log
,如果Log
数据库中存在该日期,我试图从日历控件中显示所选日期。即如果选择2017-10-08
且它存在于日志数据库中,则显示数据库中2017-10-08
的所有实例。这是我走了多远。
public class Log
{
public int LogID { get; set; }
public int EmployeeID { get; set; }
public Employee Employee { get; set; }
public string Login { get; set; }
public string Logout { get; set; }
public string Date { get; set; }
}
public class SelectDate
{
public int SelectDateID { get; set; }
[DataType(DataType.Date)]
public string SelectedDate { get; set; }
}
控制器CalendarDetails
用于显示建议的问题:
public ActionResult SelectDate(string username, SelectDate date, Log logdate)
{
db.SelectDates.Add(date);
db.SaveChanges();
var getdate = from l in db.Logs
from sd in db.SelectDates
where (l.Date == sd.SelectedDate)
select l;
if (getdate != null)
{
return RedirectToAction("CalendarDetail");
}
else
{
return View();
}
}
public ActionResult CalendarDetail(string username)
{
var logTimes = db.Logs.Include(a => a.Employee);
return View(logTimes.ToList());
}