在Northwind DB中创建Controller Action CreateNewEmployee
我尝试在MVC中创建一个新的Employee。 控制器:
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();
}
服务器错误:
参数字典包含'MvcEmployee.Controllers.EmployeeController'中方法'System.Web.Mvc.ActionResult HireNew(Int32)'的非空类型'System.Int32'的参数'id'的空项。 可选参数必须是引用类型,可为空类型,或者声明为可选参数。 参数名称:参数
[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/39223.html
上一篇: creating Controller Action CreateNewEmployee in Northwind DB