Robie sobie cwiczenie (na wzor z ksiazki Freemana) z pobieraniem danych z bazy ale dostaje błąd przy foreach :
object reference not set to an instance of an object
@foreach (var p in Model)
{
Html.RenderPartial("List", p);
}
List
@model SystemZamowien.Entities.Product
<div class ="item">
<h3>@p.Opis</h3>
@p.ModelProduktu
<h4>@p.Cena.ToString("c")</h4>
</div>
Repozytorium z bazy mam zrobione:
EFProductRepository
using SystemZamowien.Abstract;
using SystemZamowien.Entities;
using System.Linq;
namespace SystemZamowien.Concrete
{
public class EFProductRepository : IProductRepository
{
private EFDbContext context = new EFDbContext();
public IQueryable<Product> Produkty
{
get { return context.Produkty; }
}
}
}
Powiązania również:
EFDbContext
using SystemZamowien.Entities;
using System.Data.Entity;
namespace SystemZamowien.Concrete
{
public class EFDbContext : DbContext
{
public DbSet<Product> Produkty { get; set; }
}
}
i jeszcze akcja kontrolera:
namespace SystemZamowien.Controllers
{
public class ProductController : Controller
{
private IProductRepository repository;
public ProductController(IProductRepository productRepository)
{
this.repository = productRepository;
}
public ViewResult Index()
{
return View(repository.Produkty);
}
}
}
W czym może być problem? Poproszę o jakieś wskazówki.