我已经为注册创建了一个WebAPI POST方法。 当我使用POSTMAN测试服务时,模型对象始终为NULL。我搜索了很多这个问题,但似乎没有什么对我有用。
我的代码如下:
public HttpResponseMessage PostStudent(EmployeeModel emp)
{
if (ModelState.IsValid)
{
using (HRMSEntities reg = new HRMSEntities())
{
APIRegistration entities = new APIRegistration();
entities.Emp_No = emp.EmpNumber;
entities.MobileNo = emp.MobileNumber;
entities.IMEINo = emp.IMEINumber;
entities.GPS_LAT = emp.GPSLatitude;
entities.GPS_LOG = emp.GPSLog;
entities.GPS_LOCATION = emp.GPSLocation;
reg.APIRegistrations.Add(entities);
reg.SaveChanges();
var response = Request.CreateResponse<EmployeeModel>(HttpStatusCode.OK, emp);
return response;
}
}
else
{
return Request.CreateErrorResponse(HttpStatusCode.NotFound, "Emplyee not found");
}
}
这是我的POST请求:
POST/api/Registration
Cache-Control →no-cache
Content-Length →26
Content-Type →application/json; charset=utf-8
Date →Wed, 25 Apr 2018 05:41:48 GMT
Expires →-1
Pragma →no-cache
Server →Microsoft-IIS/10.0
X-AspNet-Version →4.0.30319
X-Powered-By →ASP.NET
{"EmpNumber":"104091"
"MobileNumber":"1234567898"
"IMEINumber":"123456789256543"
"GPSLatitude":"47.54"
"GPSLog"::56.543"
"GPSLocation":"GOA"
}
我在this链接上看到了评论,并尝试了所有解决方案,但没有任何效果。我究竟做错了什么??
答案 0 :(得分:0)
问题已解决。 JSON参数上缺少逗号,问题得到解决。