@Foreach в представлении ссылка на объект модели не установлена на экземпляр объекта
Hi I'm getting a scary problem The controller is invoked normally, the foreach loop works fine, call the view with a List return and the @foreach start the loop and load the registers brought from the DB, but in the last interaction it brokes.
Server Error in Application '/'. Object reference not set to an instance of an object.enter image description here Exception Details: System.NullReferenceException: Object reference not defined for an instance of an object.
---> просмотр
@model IEnumerable<VitrineVirtual.Model.Carrinho_Compras> <div class="ibox-content"> <table class="footable table table-stripped toggle-arrow-tiny" data-page-size="15"> <tbody> @foreach (var item in Model.Where(item => item != null)) { <tr> <td> <div class="product-detail"> <ul> <li><span>@Html.DisplayFor(modelItem => item.Nome_Produto)</span></li> <li><span>@Html.DisplayFor(modelItem => item.Modelo_Produto)</span></li> <li><span>@Html.DisplayFor(modelItem => item.Descricao_Produto)</span></li> </ul> </div> </td>
Что я уже пробовал:
I tried to do with viewdata, viewbag, IEnumerable, List, IList every possibilities but nothing. Is somebody have any spirit and glourious solution? Thanks a lot. The variable names it´s in portuguese, but I keeped the main names like dbcontext in ingles or the standar initials.