I set the E_id as a primary key.My Edit function is not working.It continuously throws the error.But my create and index functions working good.What will be the problem in my code?This is the ERROR
[ArgumentException: The parameters dictionary contains a null entry for parameter 'id' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResult Edit(Int32)' in 'BusinessObjects.Controllers.EmployeeController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter. Parameter name: parameters]
public ActionResult Index()
{
EmployeeBusinessLayer employeebusinesslayer = new EmployeeBusinessLayer();
List<Employee> employees = employeebusinesslayer.Employees.ToList();
return View(employees);
}
[HttpGet] //Create after this Get
[ActionName("Create")] //old name of function
public ActionResult Create_get()
{
return View();
}
[HttpGet]
public ActionResult Edit(int id)
{
EmployeeBusinessLayer employeebusinesslayer = new EmployeeBusinessLayer();
Employee employee = employeebusinesslayer.Employees.Single(emp => emp.E_id == id);
return View(employee);
}
[HttpPost] //Create after this Get
[ActionName("Create")]//old name of function
public ActionResult Create_post()
{
if (ModelState.IsValid)
{
Employee employee = new Employee();
UpdateModel(employee); //Updatemodel for employee - Call for new entries
EmployeeBusinessLayer employeebusinesslayer = new EmployeeBusinessLayer();
employeebusinesslayer.AddEmployee(employee);
return RedirectToAction("Index");
}
return View();
}
}
}