1
所以我想這個網址該處理的POST
請求數轉換:轉換的URL,查詢字符串
// this works
http://localhost/api/locations/postlocation/16/555/556
,其被認爲是其equavalent查詢字符串:
http://localhost/api/locations/postlocation?id=16&lat=88&lon=88
但是當我正在做這個我得到這個錯誤。顯然,它不承認的參數之一:
"Message": "An error has occurred.",
"ExceptionMessage": "Value cannot be null.\r\nParameter name: entity",
"ExceptionType": "System.ArgumentNullException",
這是處理這個帖子請求的方法:
[Route("api/locations/postlocation/{id:int}/{lat}/{lon}")]
public IHttpActionResult UpdateUserLocation(string lat, string lon, int id)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
var user = db.Users.FirstOrDefault(u => u.Id == id);
if (user == null)
{
return NotFound();
}
var userId = user.Id;
var newLocation = new Location
{
Latitude = Convert.ToDouble(lat),
Longitude = Convert.ToDouble(lon),
User = user,
UserId = user.Id,
Time = DateTime.Now
};
var postLocation = PostLocation(newLocation);
return Ok();
}
任何想法有什麼問題呢?
如果同時添加'Route's,那麼它不會破壞第一個示例。 –