传递到字典中的模型项的类型为,我将如何传递带有变量的orders_tables模型 [英] The model item passed into the dictionary is of type , how i will pass orders_tables model with variable

查看:71
本文介绍了传递到字典中的模型项的类型为,我将如何传递带有变量的orders_tables模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么会出现此错误:

传递到字典中的模型项的类型为'AljawdahNewSite.Models.Orders_Tables',但此字典需要模型项的类型为'System.Collections.Generic.IEnumerable`1 [AljawdahNewSite.Models.Orders_Tables]'.

这是模型Orders_Tables:

This is the model 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>();
        }


    }

这是控制器:

public ActionResult ordersCash1()
        {
            Orders_Tables tables = new Orders_Tables();

            var OrdersList = from o in tables.LabOrdersCash
                             join st in tables.LabOrderStatus on o.order_status equals st.status_id
                             where o.patient_no == (int)Session["UserpatientNo"]
                             select o;


            return View(OrdersList);
         }

这是查看代码:

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

<h2>Orders List</h2>

<table class="table">
        <tr>
            <td> Order No. </td>
            <td> order date    </td>
            <td> MRN Patient No  </td>
            <td> Order Status   </td>


        </tr>
        @foreach (var item in Model)
        {
            <tr>
                <td>@item.LabOrdersCash.First().cash_order_id</td>
                <td>@item.LabOrdersCash.First().order_date</td>
                <td>@item.LabOrdersCash.First().patient_no</td>
                <td>@item.LabOrderStatus.First().status_name</td>
                <td>@Html.ActionLink("Result Details", "Details1", new { id = item.LabOrdersCash.First().cash_order_id })</td>
            </tr>
        }
    </table>

如何解决此错误,我在站点中检查了解决方案,但情况不同?

how to solve this error i checked solutions in the site but its different cases ?

推荐答案

在操作中,尝试选择 oreders Cach sample Status 的列表并将其添加到 tables 对象,如以下代码所示:

In the action, try to select list of oreders Cach and sample Status and add them to tables object like the following code :

public ActionResult ordersCash1()
{
    Orders_Tables tables = new Orders_Tables();
    int patientId = (int)Session["UserpatientNo"];

    var result  = (from o in db.Lab_orders_Cash
                 join st in db.Lab_Sample_status on o.order_status equals st.status_id
                 where o.patient_no == patientId
                 select new {orederCach = o, sampleStatus = st}).ToList();

    tables.LabOrdersCash = result.Select(x => x.orederCach).ToList();
    tables.LabOrderStatus = result.Select(x => x.sampleStatus).ToList();

    return View(tables);
 }

`在视图中,将模型更改为:

` In the view, change the model to :

@model AljawdahNewSite.Models.Orders_Tables

如果仅搜索 LabOrdersCash LabOrderStatus

....
    <tr>
        <td>@Model.LabOrdersCash.First().cash_order_id</td>
        <td>@Model.LabOrdersCash.First().order_date</td>
        <td>@Model.LabOrdersCash.First().patient_no</td>
        <td>@Model.LabOrderStatus.First().status_name</td>
        <td>@Html.ActionLink("Result Details", "Details1", new { id = item.LabOrdersCash.First().cash_order_id })</td>
    </tr>

希望您对此有帮助.

这篇关于传递到字典中的模型项的类型为,我将如何传递带有变量的orders_tables模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆