原后台代码:
[HttpGet]
public PartialViewResult GetInfo(string hospitalid)
{
IQueryable<THospitalOrder> orderList = null;
if (hospitalid != null && hospitalid != "")
{
int HospitalID=Int32.Parse(hospitalid);
orderList = THospitalOrderRepository.GetMany(m => m.HospitalID == HospitalID);
}
return PartialView("_GetInfo", orderList);
}
cshtml视图代码:
<pre name="code" class="html">@model IQueryable
@if(Model.Count()==0){
<strong>~暂无记录~</strong>
}else{
foreach(THospitalOrder m in Model) {
<fieldset style="border: 2px solid grey; padding: 10px; margin: 0px">
<legend style="color: #A86500"><strong>订单编号:@m.OrderNumber</strong></legend>
<table class="table ">
<tbody>
<tr>
<td>
联系方式:
</td>
<td>
@m.GetTel
</td>
<td>
联系地址:
</td>
<td>
@m.GetAddress
</td>
<td>
备注信息:
</td>
<td>
@m.OrderRemark
</td>
</tr>
@foreach (THospitalOrderItem OrderItem in @m.THospitalOrderItems) {
<tr> <td>@OrderItem.TProduct.ProductName</td> <td>@OrderItem.TotalCount</td> <td>@OrderItem.TotalPrice</td> </tr>
}
</table> </fieldset> }
}
<pre name="code" class="html">运行时一直报错,错误信息“已有打开的与此+Command+相关联的+DataReader,必须首先将它关闭。”
解决方法:将数据源改为List格式输出。
[HttpGet]
public PartialViewResult GetInfo(string hospitalid)
{
<span style="color:#ff0000;"> List<THospitalOrder> orderList = null;</span>
if (hospitalid != null && hospitalid != "")
{
int HospitalID=Int32.Parse(hospitalid);
orderList = THospitalOrderRepository.GetMany(m => m.HospitalID == HospitalID).<span style="color:#ff6666;">ToList();</span>
}
return PartialView("_GetInfo", orderList);
}