2017-01-06 81 views
0

下面是我的局部视图呼叫:对象引用呈现局部视图

<div id="div-reviewgrid"> 

         @Html.Partial("_ReviewList", ViewBag.RewiewLists as List<Pollit.Data.Review>) 

        </div> 

这是我的共享文件夹中的局部视图,下部分:

@using Pollit.Data; 

@{ 
    List<Review> reviewList = ViewBag.RewiewLists; 
} 

<br /><br /> 

@if (reviewList != null) 
{ 
    foreach (var review in reviewList) 
    { 
     <div class="col-lg-12"> 
      <div id="@review.Id"> 
       <div class="col-lg-1 col-md-1 col-xs-12 col-sm-12"> 
        @if (review.Rating != null) 
        { 
         <img src="/images/ratings/@review.Rating.Number-bars.png" class="pull-left" style="max-height: 50px; max-width: 50px; margin-left: 30px" /> 
        } 
       </div> 
       <div class="col-lg-11 col-md-11 col-xs-12 col-sm-12"> 
        <span>@review.Creator.Name &nbsp;@String.Format("{0:d}", review.Created)</span> 
        <br /> 

        <h4 class="custum-memphisfontmediumitalic ">@review.Content</h4> 
        @*<input type="submit" value="Like" class="btn btn-info" /> 
         <input type="submit" id="click" value="Comment" class="btn btn-info" /> 
         <input type="text" id="comment" placeholder="Enter your comment" class="form-control" />*@ 
       </div> 


      </div> 
      <br /> 
      @if (Request.IsAuthenticated == true) 
      { 

       if (review.Replys != null) 
       { 
        foreach (var reply in review.Replys.OrderBy(c => c.Created)) 
        { 
         <div id="[email protected]" class="col-lg-8 col-md-10 col-xs-12 col-sm-12 col-lg-offset-1 "> 



          <span>Reply By:@reply.Creator.Name &nbsp;@String.Format("{0:d}", @reply.Created)</span> 
          <br /> 
          <h4 class="custum-memphisfontmediumitalic">@reply.ReplyContent</h4> 
         </div> 
        } 
       } 

       <div class="col-lg-8 col-md-10 col-xs-12 col-sm-12 col-lg-offset-1 form-group "> 
        <input type="text" id="[email protected]" placeholder="Enter your reply" class="form-control" /> 
       </div> 
       <div class="col-lg-2 form-group"><div class="demo"> 
       <a href= "SubmitReply(@review.Id); return false;" onclick="SubmitReply(@review.Id); return false;" class="pull-right"> Reply</a> 
        <img src="/Images/Comment rate up.png" class="img-responsive" width="40px" ><img src="/Images/Comment rate down.png" class="img-responsive" width="40px" ></div> 
       </div> 
      } 
     </div> 
    } 
} 




<br /><br /> 

以上是我的部分视图代码,让我知道如果我做错了什么。请帮帮我。在此先感谢您的帮助

+1

你试图呈现部分或??的RenderAction –

+0

@TetsuyaYamamoto我已经应用调试器,当所有列表完成后,它给了我错误后​​,在我的列表中的空异常错误没有什么是空来的,我已经申请空对象检查 –

回答

0

当您打电话给你的部分视图你写错了。每次调用时,新模型生成和模型那张empty`

@Html.Partial("_ReviewList", ViewBag.RewiewLists as List<Pollit.Data.Review>) 

Model,而不是ViewBag.RewiewLists as List<Pollit.Data.Review>

相关问题