我正在研究.net核心中的API项目并遇到问题。我无法将客户端模型绑定到'客户端'在下面的方法中的变量,请注意它与[HttpPost]
归因方法一起使用。
CODE
[Route("client/{id}")]
[HttpPut]
public IActionResult UpdateClient(string id, [FromBody] Client client)
{
try
{
ObjectId objectid = new ObjectId(id);
Client update = _oauthRepository.GetClient(objectid);
if(update != null)
{
_oauthRepository.UpdateClient(objectid, client);
return Json(objectid);
}
return Json(false);
}
catch(Exception e)
{
throw e;
}
}
邮差
[Method: PUT] url: http://localhost:50122/client/5aeb1a29405f2558bc6eac84
Body (JSON(application/json)):
{
"BsonID": "5aeb1a29405f2558bc6eac84",
"clientID": "blaatje",
"clientSecrets": [
"secret"
],
"allowedScopes": "api"
}
客户模式
namespace AuthServer.Models
{
public class Client
{
[BsonId]
public ObjectId BsonID { get; set; }
public string ClientID { get; set; }
public IEnumerable<string> ClientSecrets { get; set; }
public string AllowedScopes { get; set; }
}
}
答案 0 :(得分:0)
<强>邮差强>
[Method: PUT] url: http://localhost:50122/client/5aeb1a29405f2558bc6eac84
Body (JSON(application/json)):
{
//"BsonID": "5aeb1a29405f2558bc6eac84", // <-- Leave this line out and it works, probably because this is a MongoDB attributed property
"clientID": "blaatje",
"clientSecrets": [
"secret"
],
"allowedScopes": "api"
}
现在转到下一个错误,但是这个错误超出了这个问题的范围:)