-3

I got the error Message:

CS0120 - An object reference is required for the non-static field, method, or property 'StageDBEntities.Aufgaben'

My Code:

public ActionResult AufgabenDetails(int id)
{
    var Aufgabe = StageDBEntities.Aufgaben.Find(id);

    return View(Aufgabe);

}

This Code is on my Main Controller. With this i try to create a Site per Task(Aufgabe) in my Database. /AufgabenDetails/1 <-- one is the ID of my Task(Aufgabe)

  • whether StageDBEntities is a class ? and it is not a static class to use StageDBEntities.Aufgaben, you have to create object of StageDBEntities and need to access – Visakh V A Oct 14 '16 at 08:46
  • Did you look at the related column on the right? There are at least 10 duplicates of this error. Why you don't search before asking? – Steve Oct 14 '16 at 08:48

2 Answers2

0

You should creat an instance of StageDBEntities before trying to use it. Try

public ActionResult AufgabenDetails(int id)
{
    var Aufgabe = new StageDBEntities().Aufgaben.Find(id);

    return View(Aufgabe);

}
Owuor
  • 616
  • 6
  • 10
0

If StageDBEntities is your Entity Framework class, you need to instantiate a new db instance as a variable

public ActionResult AufgabenDetails(int id)
{

    StageDBEntities db = new StageDBEntitites();
    var Aufgabe = db.Aufgaben.Find(id)

    return View(Aufgabe);

}
Alfie Goodacre
  • 2,753
  • 1
  • 13
  • 26