0

我尝试在 MVC 中创建一个新员工。控制器 :

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”的空条目。可选参数必须是引用类型、可空类型或声明为可选参数。参数名称:参数

4

1 回答 1

0
   [HttpPost]
        public ActionResult Create(Employee employee)
        {
            try
            {
                NorthwindEntities northwindEntities = new NorthwindEntities();
                northwindEntities.Employees.Add(employee);
                northwindEntities.SaveChanges(); 

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
于 2013-04-10T18:24:20.690 回答