0

I am as many others following the MVC Music Store Tutorial, but I'm stuck with an error.

At page 48, the tutorial says to write an ActionResult-view:

 public ActionResult Index()
    {
        var genres = storeDb.Genres.ToList()

        return View(genres);
    }

but I get an error on genres. Visual Web Developer says "value cannot be null".

what should I set genres to? var genres = new ??

Thank you!

1 Answer 1

2

Make sure you have specified a connection string to your database in web.config. Also make sure you initialize the storeDb variable before using it:

public ActionResult Index()
{
    var storeDb = new StoreDbDataContext(); // Replace this with the actual type
    var genres = storeDb.Genres.ToList();
    return View(genres);
}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.