Object reference not set to an instance of an object - Partial View

前端 未结 2 1861
傲寒
傲寒 2020-12-22 09:05

I have a strongly typed partial view which is giving me \"Object reference not set to an instance of an object\" error when I launch the master view. I know I am not passing

2条回答
  •  离开以前
    2020-12-22 09:43

    You have to pass some Model to your partialView, because it need a instance of IEnumerable

    <% Html.RenderPartial("DisplayPartial", model); %>
    

    Or, you can check in your partial view if the model is not null.

    <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl>" %>
    
    
    <% if (Model != null) {
         foreach (var item in Model) {
               if (item == null) continue; %>
    
                        
                
                    <%: item.Item1%>
                
                
                    <%: item.Item2%>
                
            
    
        <% }
    } %>
    
        
    

提交回复
热议问题