使用 id 的 MVC

MVC working with id's

我有这个显示作业订单操作

public ActionResult jobOrderList(int id)
{
     var SelectedTruck = db.trucks.FirstOrDefault(s => s.id == id);

     List<JobOrderDetails> joList = db.joborders.Select(s => new JobOrderDetails()
     {

         id = s.id,
         DateStarted = s.date_started,
         Description = s.description,
         DateFinished = s.date_finished,
         SpareParts = s.spare_parts,
         kilometer_run = s.run,
         Quantity = s.quantity,
         truck_no = s.truck_no,
         worked_performed = s.worked_performed

     }).ToList();

     return View(joList);
}

如何显示所选卡车变量的作业单列表。

我相信这就是您要问的。

     var SelectedTruck = db.trucks.FirstOrDefault(s => s.id == id);

List<JobOrderDetails> joList = db.joborders.Where(jo => jo.truck_no == SelectedTruck.truck_no).Select(s => new JobOrderDetails()
                 {

                     id = s.id,
                     DateStarted = s.date_started,
                     Description = s.description,
                     DateFinished = s.date_finished,
                     SpareParts = s.spare_parts,
                     kilometer_run = s.run,
                     Quantity = s.quantity,
                     truck_no = s.truck_no,
                     worked_performed = s.worked_performed

                 }).ToList();