为什么我在Web api中的post方法上出现500错误?它在数据库中创建记录,但显示500错误

时间:2018-12-17 06:10:18

标签: rest api web asp.net-web-api

我遇到的错误

  

“消息”:“发生错误。”,       “ ExceptionMessage”:“ UrlHelper.Link不能返回null。       “ ExceptionType”:“ System.InvalidOperationException”,

[Route(UrlClass.createEmployee)]

    [HttpPost]
    public IHttpActionResult createEmployee(Employee employee)
    {
        if (!ModelState.IsValid)
        {
            return BadRequest(ModelState);
        }

        db.Employees.Add(employee);

        try
        {
            db.SaveChanges();
        }
        catch (DbUpdateException)
        {
            if (EmployeeExists(employee.Employee_ID))
            {
                return Conflict();

            }
            else
            {
                throw;
            }
        }

        return CreatedAtRoute("GetAction", new { id = employee.Employee_ID }, employee);
    }

0 个答案:

没有答案
相关问题