It looks like you are getting the disposed error because its wrapped inside of a using statement and you are passing the value through the ViewBag. You should really create a model for this and pass it using the model to the view.
Model
public Class MyModel
{
public SelectListItem DepartmentMaster { get; set; }
}
Controller
public ActionResult GetAllDepartment()
{
using (var db = new TestEntities())
{
MyModel model = new Model();
IEnumerable<SelectListItem> items = db.DepartmentMasters.Select(c => new SelectListItem
{
Value = c.DepartmentID.ToString(),
Text = c.DepartmentName
});
model.DepartmentMaster = items;
return View(model);
}
}
Model
@model MvcApplication4.Models.DepartmentMaster
@{
ViewBag.Title = "GetAllDepartment";
}
<h2>GetAllDepartment</h2>
@using (Html.BeginForm())
{
@Html.DropDownList("DepartmentID", Model.DepartmentMaster)