ASP.NET MVC Exception The operation cannot be completed because the DbContext has been disposed.
  • Hello 
    I am using Asp.net MVC and i am having following exception in My Razor view code


     The operation cannot be completed because the DbContext has been disposed. 
    I am having following code

    Controller.cs


      public ActionResult ShowStudents() 
    {

    using (var ctx = new SMSContext())

    {
    string StudentName = "Sajid";
    var query = from Student in ctx_1.Students select Student;

    ViewBag.std = query;
    return View();

    }



    }
    }




    In myview.cshtml I have

      @foreach (var student in ViewBag.std)
    {
    <tr>
    <td> @student.StudentName </td>
    <td> @student.DateOfBirth </td>
    <td> @student.Weight </td>
    <td> @student.Height </td>

    </tr>
    }



    Exception is thrown at line where i am having @foreach code.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, or you want to Ask a new Question, Please Login or Create a new Account by Clicking below

Login with Facebook

Popular Posts of the Week

    Optimum Creative