2

Following is my get method in ASP.NET Web API.

[HttpGet]
public IHttpActionResult GetDetails([FromBody] RetrieveDetails  eDetails)
{}

following is the class

public class RetrieveDetails
{ 
    public string name{ get; set; }     
    public string Type { get; set; } 
}     

When I try to call GetDetails from Fiddler eDetails is always null.

http://localhost:101222/api/emailservice/GetDetails?name=testname&Type=testtype

I tried different methods but the value is always null. If I change [HttpGet] to [HttpPost] and add the request body its working fine. But I need get method.

mason
  • 31,774
  • 10
  • 77
  • 121
user8383606
  • 31
  • 1
  • 1
  • 6

1 Answers1

2

Do you need [FromBody] there if you are passing values in URL for GET. You should be using [FromUri] if you are passing values in querystring.

https://learn.microsoft.com/en-us/aspnet/web-api/overview/formats-and-model-binding/parameter-binding-in-aspnet-web-api

Amit Kumar Singh
  • 4,393
  • 2
  • 9
  • 22