仅当不是空值时搜索



我目前正在编写一个搜索功能,通过票主,票务技术,状态等搜索门票。然而,我想我可以把if语句放在Linq语句测试的中间,如果不是null,不幸的是,我在Linq语句中得到了if语句的错误。这是我的控制器代码:

 public ActionResult TechSearchTickets()
        {
            ViewBag.StatusId = new SelectList(db.TicketStatuses, "UserId", "FullName");
            ViewBag.UserId = new SelectList(db.Users
                                                .Where(u => u.Status == 1 || u.RoleID == new Guid("00000000-0000-0000-0000-000000000000")), "UserId", "FullName");
            ViewBag.TechId = new SelectList(db.Users
                                                .Where(u => u.Status == 1 || u.RoleID == new Guid("00000000-0000-0000-0000-000000000000")), "UserId", "FullName");
            return View();
        }
        [HttpPost]
        public ActionResult TechSearchTickets(SearchTickets searchTickets)
        {
            var model = db.Tickets
                    .Include(t => t.TicketNotes)
                    if (searchTickets.TechnicianId != null)
                    {
                        .Where(t => t.TechnicianId == g)
                    }
                    .Where(t => t.TicketStatusId == new Guid("553F4C93-4A72-44BD-A9CE-FAB4F87D4E08"))
                    .OrderBy(t => t.OpenDate)
                    .ToList();
            return View("TechClosed", model);

            return View();
        }

关闭。您只需要添加几个分号,和model=model

var model = db.Tickets
  .Include(t => t.TicketNotes);
if (searchTickets.TechnicianId != null)
{
  model=model.Where(t => t.TechnicianId==g);
}
model=model.Where(t => t.TicketStatusId==new Guid("553F4C93-4A72-44BD-A9CE-FAB4F87D4E08"))
  .OrderBy(t => t.OpenDate);
var result=model.ToList();

相关内容

  • 没有找到相关文章

最新更新