2017-04-22 40 views
-1

我正在购买购物车应用程序。它已经由一些开发者开发。但我试图重建它,但我得到了以下异常在App_Web_jwfiir5n.dll中发生类型'System.NullReferenceException'的异常,但未在用户代码中处理

型“System.NullReferenceException”的异常出现在App_Web_jwfiir5n.dll但在用户代码中没有处理 其他信息:对象引用未设置为一个实例的一个对象。

的代码我的观点是如下:

<tbody> 
       @foreach (var item in Model) 
       { 
        <tr> 
         <td>@(Model.IndexOf(item) + 1)</td> 
         <td><a style="color:cornflowerblue" title="Click to see the product detail" href="/admin/[email protected]"> @item.Tbl_Product.ProductName</a></td> 
         <td>@(item.Tbl_Members.FirstName + " " + item.Tbl_Members.LastName)</td> 
         <td>@item.Tbl_Members.EmailId</td> 
        </tr> 
       } 
      </tbody> 

发生了。控制器侧的下方是:

public ActionResult OrderDetail(int productId) 
{ 
    List<Tbl_Cart> ProductOrders = _unitOfWork.GetRepositoryInstance<Tbl_Cart>().GetListByParameter(i => i.CartStatusId == 3 && i.ProductId == productId).ToList(); 
    return View(ProductOrders); 
} 

谁能帮我这个错误。

+2

的【什么是一个NullReferenceException,如何解决呢?(可能的复制http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception -and-怎么办-I-FIX-IT) –

回答

0

检查空

<tbody> 
if(Model != null) 
{ 

    @foreach (var item in Model) 
    { 
     <tr> 
      <td>@(Model.IndexOf(item) + 1)</td> 
      <td><a style="color:cornflowerblue" title="Click to see the product detail" href="/admin/[email protected]"> @item.Tbl_Product.ProductName</a></td> 
      <td>@(item.Tbl_Members.FirstName + " " + item.Tbl_Members.LastName)</td> 
      <td>@item.Tbl_Members.EmailId</td> 
     </tr> 
    } 

} 
</tbody> 
相关问题