.Net MVC 视图双层foreach嵌套

原后台代码:
[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);
        }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值