0

I want to select data from multiple tables and view. I created the following class Orders tables:

public class Orders_Tables
    {
        public List<Lab_Orders>  LabOrders { get; set; }
        public List<Lab_orders_Cash> LabOrdersCash { get; set; }
        public List<Lab_Sample_status> LabOrderStatus { get; set; }

        public List<LAB_RESULTS> LabResults { get; set; }
        public List<LabTests> labtests { get; set; }
        public List<LAB_RESULTS_CLINIC_VIEW> labViewResult { get; set; }
        public List<LAB_RESULT_CASH_VIEW> labCashView { get; set; }

        public List<LAB_PARASITOLOGY_VIEW> labparaview { get; set; }

       public List<Lab_Hematology_Samples> LabSamples { get; set; }

      public List<Patients> patients { get; set; }

        public Orders_Tables()
        {
            this.LabOrders = new List<Lab_Orders>();
            this.LabOrdersCash = new List<Lab_orders_Cash>();
            this.LabOrderStatus = new List<Lab_Sample_status>();
            this.LabResults = new List<LAB_RESULTS>();
            this.labtests = new List<LabTests>();
            this.labViewResult = new List<LAB_RESULTS_CLINIC_VIEW>();
            this.labCashView = new List<LAB_RESULT_CASH_VIEW>();
            this.labparaview = new List<LAB_PARASITOLOGY_VIEW>();
            this.LabSamples = new List<Lab_Hematology_Samples>();
            this.patients = new List<Patients>();
        }


    } 

And this is the controller :

public ActionResult Cash(int id)
        {
            Orders_Tables tables = new Orders_Tables();
            tables.labCashView = db.LAB_RESULT_CASH_VIEW.Where(c => c.order_number == id).ToList();
            tables.labparaview = db.LAB_PARASITOLOGY_VIEW.Where(p => p.ORDER_ID == id).ToList();

            return View(tables);
        }

Then I created empty view , the error when i try to select columns i cannot find it and the error appeared when i paste the column name , this is the view code :

@model IEnumerable<AljawdahNewSite.Models.Orders_Tables>
@{
    ViewBag.Title = "Cash";
    Layout = "~/Views/Shared/_LayoutPatients.cshtml";
}

    <div id="divprint">
        <div style="margin-left:15px">
            <hr />
            <dl class="horizontal" style="border:solid">
                <dt style="width: 20%;display: inline-block;color:blue;">@Html.DisplayNameFor(model => model.labCashView.Patient_Name)</dt>
                <dd style="width: 25%;display: inline-block;margin: 0px;margin-left:-50px">@Html.DisplayFor(model => model.FirstOrDefault().labCashView.Patient_Name)</dd>
                <dt style="width: 22%;display: inline-block;color:blue;">@Html.DisplayNameFor(model => model.labCashView.Customer_Name)</dt>
                <dd style="width: 25%;display: inline-block;margin: 0px;margin-left:0px">@Html.DisplayFor(model => model.FirstOrDefault().labCashView.Customer_Name)</dd>
              </dl>
        </div>

The error appeared when i paste the column name : Patient_Name , Customer_Name and so on ...

list lab_result_cash_view does not contain a definition for 'Patient_Name ' and no extension method 'Patient_Name ' accepting a first argument of type 'list lab_result_cash_view could not be found are you missing a using directive or an assembly reference

How i will select column name in the view ?

Mohammed Sajid
  • 4,778
  • 2
  • 15
  • 20
Abdullah
  • 983
  • 12
  • 26

1 Answers1

1

After comment, you could take the first element and access to the property like the following code :

@Html.DisplayNameFor(model => model.labCashView.First().Patient_Name)
Mohammed Sajid
  • 4,778
  • 2
  • 15
  • 20
  • Jazak allah khir , for sure i need your help a lot i am new to MVC and I want to build Medical Laboratory system :) – Abdullah May 28 '20 at 01:08