Click here to Skip to main content
15,887,175 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
problem

when pass id value of put(update) from postman it passed as 0 although it have value on link ?

C#
i select key from post man as contenttype application/json

and this is my url

https://localhost:44326/api/Employee/put?id=5


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();
        }
Posted
Updated 20-Feb-19 18:35pm

1 solution

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.
 
Share this answer
 
Comments
GSThakur 30-Mar-21 0:38am    
If the solution worked for you, please mark as accepted solution.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900