Forums - C# Corner

Forum guidelines
Harish Batchu

Harish Batchu

  • 1.6k
  • 196
  • 5.8k

I am getting null value when request hitting to controller?

May 23 2019 8:06 AM
I am developing Web API in dot net core 2.1. When i am passing the values through postman the request hitting to controller but the value is not getting
 
Below is my code
  1. namespace MilkPos.API.Controllers  
  2. {  
  3. [Route("api/")]  
  4. public class HomeController : ControllerBase  
  5. {  
  6. IUser _IUser;  
  7. private DatabaseContxt _context;  
  8. public HomeController(IUser user,DatabaseContxt context)  
  9. {  
  10. _IUser = user;  
  11. _context = context;  
  12. }  
  13. //[Route("api/Order/{StatusId}/Status/{OrderId}/Order")]  
  14. [Route("GetOtp")]  
  15. [HttpPost("{id}")]  
  16. public ActionResult GetOtp(long id)  
  17. {  
  18. int otp = 0;  
  19. return Ok(id);  
  20. }  
  21. [Route("GetGeneratedOtp")]  
  22. [HttpPost]  
  23. public ActionResult GetGeneratedOtp(int Number)  
  24. {  
  25. return Ok(Number);  
  26. }  
  27. }  
  28. }  
Form postman i am calling like:
 
http://localhost:8000/api/GetOtp/
 
Header
key content-type
value application/json
Body {"id":328432}
 
i am getting 0

Answers (3)