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.

2
  • Change [FromBody] to [FromUri] and your url should work. Commented Aug 19, 2017 at 1:30
  • I changed it to [FromUri] , its working.Thanks a lot. Commented Aug 21, 2017 at 2:11

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.