Tom Limpens Tom Limpens - 3 years ago 196
ASP.NET (C#) Question

ASP.NET model won't load my repository

When I try to load my repository into my view like this

@model BlueRateITRepositories.Repository.FilmRepository;
@{
ViewBag.Title = "Films";
}

<h2>Films</h2>


The model gives the error "'FilmRepository' is a type which is not valid in the given context"

Controller code

FilmRepository FilmRepository = new FilmRepository();

// GET: Film
public ActionResult Films()
{
return View(FilmRepository);
}


Can anyone help me fix this?

Answer Source

Remove the semicolon at the end of your model declaration.And also, as suggested by @shyju , try keeping the object name in a different casing than the class name.

Model declaration should be-

<namespace>.ClassName

Let me know if it works.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download