尝试放置,方法有两个参数,对象在正文中,布尔在url中。 但是服务和控制器之间没有连接。 控制器:
[AllowAnonymous]
[HttpPut]
[Route("putQuestionDifficulty/{id}")]
[ResponseType(typeof(Question))]
public IHttpActionResult PutQuestionDifficulty([FromBody] Question question, [FromUri] bool id)
{
var myquestion = db.Questions.Find(question);
if (id)
{
myquestion.Difficulty++;
}
else myquestion.Difficulty--;
db.SaveChanges();
return Ok(question);
}
服务:
putQuestionDifficulty(question: Question, id: boolean){
return this.http.put<Question>(`${this.baseUrl}/putQuestionDifficulty/${id}`,question);
}
答案 0 :(得分:1)
您需要调用服务并subscribe
才能读取数据
使用特定的婴儿车打电话给putQuestionDifficulty
方法
在组件中尝试类似的操作
this.putQuestionDifficulty(question, id).subscribe((res) => {
console.log(res);
});
希望这对您有帮助-编码愉快:)