问题描述
点击详细信息链接时出现此错误:
I got this error when click on details link :
CS1061:"IEnumerable"不包含"labViewResult"的定义,并且找不到找到接受类型为"IEnumerable"的第一个参数的扩展方法"labViewResult"(您是否缺少using指令或程序集引用?)
CS1061: 'IEnumerable' does not contain a definition for 'labViewResult' and no extension method 'labViewResult' accepting a first argument of type 'IEnumerable' could be found (are you missing a using directive or an assembly reference?)
这是我的模特:
public partial class LAB_RESULTS_CLINIC_VIEW
{
public int order_number { get; set; }
public int Test_Id { get; set; }
public string Test_Name { get; set; }
public string Normal { get; set; }
public Nullable<System.DateTime> Report_Date { get; set; }
public string Result { get; set; }
public string Notes { get; set; }
public string Low_Range { get; set; }
public string High_Range { get; set; }
public string Panic { get; set; }
public string Text_Range { get; set; }
public string machine_name { get; set; }
public Nullable<int> Customer_No { get; set; }
public string Customer_Name { get; set; }
public Nullable<int> Patient_No { get; set; }
public string Patient_Name { get; set; }
public string Clinic_File_No { get; set; }
public string Category { get; set; }
public Nullable<int> AGE { get; set; }
public string SEX { get; set; }
public string Test_Note { get; set; }
public string UNIT { get; set; }
public Nullable<int> DEPTID { get; set; }
public Nullable<System.DateTime> Collection_Date { get; set; }
public Nullable<System.DateTime> Receiving_Date { get; set; }
public string Group_Name { get; set; }
public Nullable<int> SERIAL { get; set; }
public int GROUPID { get; set; }
public Nullable<int> packageid { get; set; }
public string EXAMINED_BY { get; set; }
public string APPROVED_BY { get; set; }
public string UPDATED_BY { get; set; }
public Nullable<System.DateTime> UPDATED_DATE { get; set; }
public string Comments { get; set; }
public string department_name { get; set; }
}
}
我创建了一个表类orders_tables:
and i created a tables class orders_tables :
public class Orders_Tables
{
public Lab_Orders LabOrders { get; set; }
public Lab_orders_Cash LabOrdersCash { get; set; }
public Lab_Sample_status LabOrderStatus { get; set; }
public LAB_RESULTS LabResults { get; set; }
public LabTests labtests { get; set; }
public LAB_RESULTS_CLINIC_VIEW labViewResult { get; set; }
public Lab_Hematology_Samples LabSamples { get; set; }
public Patients patients { get; set; }
}
然后这是我的控制器:
public ActionResult MasterDetails(int id)
{
List<LAB_RESULTS_CLINIC_VIEW> Lab_View = db.LAB_RESULTS_CLINIC_VIEW.ToList();
var OrderResult = from o in Lab_View
where o.order_number == id
select new Orders_Tables { labViewResult = o };
return View(OrderResult);
}
最后这是我的观点:
@model IEnumerable<AljawdahNewSite.Models.Orders_Tables>
@{
ViewBag.Title = "MasterDetails";
Layout = "~/Views/Shared/_LayoutPatients.cshtml";
}
<h2>Order Result - نتائج التحاليل </h2>
<div style="margin-left:20px">
<hr/>
<dl class="horizontal">
<dt>@Html.DisplayNameFor(model => model.labViewResult.Patient_Name)</dt>
<dd>@Html.DisplayFor(model => model.labViewResult.Patient_Name)</dd>
<dt>@Html.DisplayNameFor(model => model.labViewResult.Patient_No)</dt>
<dd>@Html.DisplayFor(model => model.labViewResult.Patient_No)</dd>
<dt>@Html.DisplayNameFor(model => model.labViewResult.SEX)</dt>
<dd>@Html.DisplayFor(model => model.labViewResult.SEX)</dd>
<dt>@Html.DisplayNameFor(model => model.labViewResult.AGE)</dt>
<dd>@Html.DisplayFor(model => model.labViewResult.AGE)</dd>
<dt>@Html.DisplayNameFor(model => model.labViewResult.order_number)</dt>
<dd>@Html.DisplayFor(model => model.labViewResult.order_number)</dd>
</dl>
</div>
<div style="align-content:center">
<table class="table table-bordered">
<tr>
<td> test name </td>
<td> result </td>
<td> From Range </td>
<td> To Range </td>
<td> Other Range </td>
<td> Report Date </td>
</tr>
@foreach (var item in Model)
{
<tr>
<td>@item.labViewResult.Test_Name</td>
<td>@item.labViewResult.Result</td>
<td>@item.labViewResult.Low_Range</td>
<td>@item.labViewResult.High_Range</td>
<td>@item.labViewResult.Text_Range</td>
<td>@item.labViewResult.Report_Date</td>
</tr>
}
</table>
</div>
该错误出现在displatyfor行中
The error appeared in displatyfor rows
如何解决此错误,我在此站点上检查了解决方案,但未解决.
How to solve this error , I checked solutions in this site but not solved .
推荐答案
您只能通过使用FirstOrDefault()或First()来解决它,但使用First()可能会解决,如果空订单将得到错误序列不包含任何元素"因此建议使用FirstOrDefault():
You can solve it by using FirstOrDefault() or First() only but with First() maybe if the order empty will get error "Sequence contains no elements" so the recommended to use FirstOrDefault() :
<dt>@Html.DisplayNameFor(model => model.labViewResult.Patient_Name)</dt>
<dd>@Html.DisplayFor(model => model.FirstOrDefault().labViewResult.Patient_Name)</dd>
<dt>@Html.DisplayNameFor(model => model.labViewResult.Patient_No)</dt>
<dd>@Html.DisplayFor(model => model.FirstOrDefault().labViewResult.Patient_No)</dd>
<dt>@Html.DisplayNameFor(model => model.labViewResult.SEX)</dt>
<dd>@Html.DisplayFor(model => model.FirstOrDefault().labViewResult.SEX)</dd>
<dt>@Html.DisplayNameFor(model => model.labViewResult.AGE)</dt>
<dd>@Html.DisplayFor(model => model.FirstOrDefault().labViewResult.AGE)</dd>
<dt>@Html.DisplayNameFor(model => model.labViewResult.order_number)</dt>
<dd>@Html.DisplayFor(model => model.FirstOrDefault().labViewResult.order_number
关于将dt和dd串联的问题,您可以将某种样式应用于dt和dd,您可以尝试以下操作:
And about your question to concatenate dt and dd you can apply some style to dt and dd , you can try the following :
<dt style="width: 30%;display: inline-block;">@Html.DisplayNameFor(model => model.labViewResult.Patient_Name)
</dt><dd style="width: 40%;display: inline-block;">@Html.DisplayFor(model => model.FirstOrDefault().labViewResult.Patient_Name)</dd>
这篇关于CS1061:"IEnumerable< Orders_Tables>"不包含"labViewResult"的定义,也没有扩展方法"labViewResult"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!