creating Controller Action CreateNewEmployee in Northwind DB
I try to create a new Employee in MVC. Controller :
HireEmployeeBL.EmployeeBL employeeBl = new HireEmployeeBL.EmployeeBL();
public ActionResult HireNew(int id)
{
return View();
}
[HttpPost]
public ActionResult HireNew(int id, Employee employee)
{
employee.ReportsTo = new Manager { EmployeeID = id };
employeeBl.AddEmployee(employee);
return RedirectToAction("Subordinates");
//return View();
}
Server Error:
The parameters dictionary contains a null entry for parameter 'id' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResult HireNew(Int32)' in 'MvcEmployee.Controllers.EmployeeController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter. Parameter name: parameters
[HttpPost]
public ActionResult Create(Employee employee)
{
try
{
NorthwindEntities northwindEntities = new NorthwindEntities();
northwindEntities.Employees.Add(employee);
northwindEntities.SaveChanges();
return RedirectToAction("Index");
}
catch
{
return View();
}
}
链接地址: http://www.djcxy.com/p/39224.html