Ramco Ramco

Ramco Ramco

  • 1.9k
  • 51
  • 1.5k

Post Api Error - Value cannot be null

Feb 26 2021 8:58 AM
Hi
 
I am getting this error -
 
{ "Message": "An error has occurred.", "ExceptionMessage": "Value cannot be null.\r\nParameter name: entity", "ExceptionType": "System.ArgumentNullException", "StackTrace": " at System.Data.Entity.Utilities.Check.NotNull[T](T value, String parameterName)\r\n at System.Data.Entity.DbSet`1.Add(TEntity entity)\r\n at ProjectManagement.Controllers.EmployeesController.PostEmployee(Employee employee) in C:\\Users\\jagji\\documents\\visual studio 2015\\Projects\\ProjectManagement\\ProjectManagement\\Controllers\\EmployeesController.cs:line 142" }
 
Below values i entered in PostMan -
 
[ { "Id": 10, "Name": "Mark 10", "DepartmentId": 1, "Email": "abc@gmail.com", "Active": "Y", "Gender":"Male" }]
  1. public partial class Employee {  
  2.   public int ID {  
  3.     get;  
  4.     set;  
  5.   }  
  6.   public string Name {  
  7.     get;  
  8.     set;  
  9.   }  
  10.   public string Email {  
  11.     get;  
  12.     set;  
  13.   }  
  14.   public string Gender {  
  15.     get;  
  16.     set;  
  17.   }  
  18.   public Nullable < int > Salary {  
  19.     get;  
  20.     set;  
  21.   }  
  22.   public Nullable < int > DepartmentId {  
  23.     get;  
  24.     set;  
  25.   }  
  26.   public string Active {  
  27.     get;  
  28.     set;  
  29.   }  
  30.   public Nullable < System.DateTime > CreatedOn {  
  31.     get;  
  32.     set;  
  33.   }  
  34.   public Nullable < System.DateTime > UpdatedOn {  
  35.     get;  
  36.     set;  
  37.   } //public Department Department { get; set; } public virtual Department Department { get; set; } }  
Thanks

Answers (2)