C# 在寻找约会对象时有困难

C# 在寻找约会对象时有困难,c#,asp.net-mvc,search,C#,Asp.net Mvc,Search,我在搜索日期列表时遇到问题,搜索结果未显示。变量约会日期已作为日期时间保存在数据库中。这是我当前控制器中的代码: public ActionResult Index(DateTime SearchDate) { var query = from a in db.AppointmentProcedures where a.BookingStatus == false orderby a.AppointmentStartTime

我在搜索日期列表时遇到问题,搜索结果未显示。变量约会日期已作为日期时间保存在数据库中。这是我当前控制器中的代码:

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);
}

看起来您想要传递给smth的
模型
列表,但是您传递的是一个查询,因为您没有像下面这样枚举它

public ActionResult Index(DateTime SearchDate)
{
    .....    

    return View(query.ToList());
}

如果您向我们展示了视图所需的模型

看起来您希望传递给smth的
模型
列表,但您传递的是一个查询,因为您没有像这样枚举它

public ActionResult Index(DateTime SearchDate)
{
    .....    

    return View(query.ToList());
}

如果您向我们展示了您的视图所需的模型,该模型在我看来不像FORTRAN。错误在哪里?在视野中?在控制器中抛出?如果您不使用
SearchDate
,它能工作吗?您在查询中尝试过使用ToList()吗?是的,我尝试过ToList,生成错误的代码行是:其中a.AppointmentDate==Convert.ToString(SearchDate),我觉得它不像FORTRAN。错误在哪里?在视野中?在控制器中抛出?如果不使用
SearchDate
,它是否有效?您是否尝试在查询中使用ToList()?是的,我尝试了ToList,生成错误的代码行是:其中a.AppointmentDate==Convert.ToString(SearchDate)我正在使用appointmentprocedure模型的索引视图。我需要索引视图上的列表进行筛选,只显示具有搜索日期的条目。hw public class AppointmentProcedure{public int AppointmentProcedureId{get;set;}public int TreatmentId{get;set;}public int InventoryKitId{get;set;}public int EmployeeId{get;set;}公共日期时间任命日期{get;set;}公共日期时间任命开始时间{get;set;}公共日期时间任命结束时间{get;set;}}请在
@model….
行中显示视图中写入的内容,并在
查询中尝试了
ToList()
(我假设您使用它)但是您传递给MVC的模型类view@modelIEnumerablei正在使用appointmentprocedure模型的index视图。我需要index视图上的列表进行筛选,并仅显示具有搜索日期的条目。hw public class AppointProcedure{public int AppointmentProcedureId{get;set;}public int TreatmentId{get;set;}public int InventoryKitId{get;set;}public int EmployeeId{get;set;}public DateTime AppointmentDate{get;set;}public DateTime AppointmentStartTime{get;set;}public DateTime AppointmentEndTime{get;set;}}请在
@model….
行中显示视图中写入的内容,并且您是否尝试过在
查询中使用
ToList()
,而不是实体模型(我假设您使用它),而是传递给MVC的模型类view@model数不清