I get a NullReferenceException when try to run a view.
I don't see the code that cause this problem.
Can someone explain the problem? thanks
This is the Model class:
public class Catalogus: ICatalogus
{
private readonly DbSet<Materiaal> materialen;
private IEnumerable<Materiaal> materialenTest;
private Firma firma;
public Catalogus()
{
firma = new Firma("hh", "[email protected]");
materialenTest = new Materiaal[] { new Materiaal(5, 0, "1", "test", "test", "ts", firma, "wereldbol", "wereldbol", "lol", 0, true) };
}
public IEnumerable<Materiaal> VindAlleMaterialen()
{
return materialenTest.OrderBy(m => m.Naam);
}
public IEnumerable<Materiaal> ZoekOpTrefwoord(string trefwoord)
{
IEnumerable<Materiaal> gefilterdMaterialen = materialenTest.Where(mat => mat.GetType().GetProperty("naam").GetValue(this).Equals(trefwoord));
return gefilterdMaterialen;
}
}
The controller with the NullRef exception:
This line cause the problem.
IEnumerable materialen = catalogus.VindAlleMaterialen().OrderBy(m => m.Naam).ToList();
public class CatalogusController : Controller
{
private ICatalogus catalogus;
public CatalogusController() { }
public CatalogusController(ICatalogus catalogus)
{
this.catalogus = catalogus;
}
public ActionResult Index()
{
IEnumerable<Materiaal> materialen = catalogus.VindAlleMaterialen().OrderBy(m => m.Naam).ToList();
return View(materialen);
}
}
Naam.