I'm trying to send the response from one of my POST methods of my webAPI controller. In the DB the values are getting saved, but while sending the response in both try and in catch it is throwing the following exception.
Exception Message: "Value cannot be null. Parameter name: request."
Controller method code:
[HttpPost]
public HttpResponseMessage AddEmployee(Employee emp)
{
try
{
using (EmployeeEntities dbEntity = new EmployeeEntities())
{
dbEntity.Configuration.LazyLoadingEnabled = false;
dbEntity.Employees.Add(emp);
dbEntity.SaveChanges();
return Request.CreateResponse(HttpStatusCode.Created, emp); // EXCEPTION IS THROWN HERE
}
}
catch(Exception ex)
{
return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex.Message);
}
}
Please let me know what i need to do to resolve this issue. Thanks.
Calling the API controller method from a MVC controller method as below,
EmployeeController empCtrl = new EmployeeController();
empCtrl.AddEmployee(emp);

Requestwhich is why yourRequestisnull.