当从邮递员传递put(更新)的id值虽然它在链接上有价值但它传递为0 [英] When pass id value of put(update) from postman it passed as 0 although it have value on link
问题描述
问题
当邮递员的传递id值为put(更新)时,虽然它在链接上有价值,却传递为0? br />
problem
when pass id value of put(update) from postman it passed as 0 although it have value on link ?
i select key from post man as contenttype application/json
and this is my url
https://localhost:44326/api/Employee/put?id=5
并在函数put中放置断点然后运行应用
它达到断点但是id返回0但是我的链接中有5个
数据库中还存在5个数据
当从角度6运行API更新时它会给我一个错误的请求,因为id传递的是0?
为什么传递id为0以及如何解决这个问题?
我w ork with asp.net core 2.1 visual studio 2017
我在控制器员工上面有这个功能
这只是我的控制器的功能更新(放)
这样如何解决问题传递0和
如果以上错误,链接是什么?
我尝试过:
and when put breakpoint in function put and run app
it hit breakpoint but id return with 0 although i have 5 in my link
and 5 also exist on database
when run API update from angular 6 it give me bad request because id is passing by 0 ?
why is pass id as 0 and how to solve this problem ?
I work with asp.net core 2.1 visual studio 2017
and I have this function above on controller Employee
this is only function update (put) for my controller
so that how to solve problem passing 0 and
what is correct link if above is wrong ?
What I have tried:
[Produces("application/json")]
[Route("api/Employee")]
public class EmployeeController : Controller
{
[HttpPut("{id}")]
public IActionResult PutEmployee(int id, [FromBody] Employee employee)
{
if (id != employee.EmployeeId)
{
return BadRequest();
}
try
{
_repository.Update(employee);
}
catch (DbUpdateConcurrencyException)
{
if (!EmployeeExists(id))
{
return NotFound();
}
else
{
throw;
}
}
return Ok();
}
推荐答案
https :// localhost:44326 / api / Employee / 5
在邮递员中选择动词Put并使用斜杠5(/ 5)传递id。
无需明确提及操作和id。
https://localhost:44326/api/Employee/5
Select verb "Put" in postman and pass id with just slash5 (/5).
No need to mention operation and id explicitly.
这篇关于当从邮递员传递put(更新)的id值虽然它在链接上有价值但它传递为0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!