我試圖在腳手架索引視圖上運行一個非常簡單的搜索。通常這適用於我,但使用日期我無法使它工作。日期搜索轉換問題
在我的控制器中的代碼是:
public ActionResult Index(DateTime SearchDate)
{
var query = from a in db.AppointmentProcedures
where a.BookingStatus == false
orderby a.AppointmentStartTime
select a;
if (SearchDate != null)
{
query = from a in db.AppointmentProcedures
orderby a.AppointmentDate
where a.AppointmentDate == SearchDate
select a;
}
return View(query);
}
但是我得到的轉換問題。在視圖中,我只有一個簡單的日期時間選擇器。
什麼是**實際錯誤?** –
DateTime不能爲空。可能發生的是SearchDate == DateTime.MinValue,並且該值沒有SQL DateTime表示。 – drch
@drch這是有道理的,假設一個日期時間總是回來,那麼當天查詢日期的方式是什麼(因爲我認爲==會假設時間) – NickP