以下是我在ASP.NET Web API中的get方法.
Following is my get method in ASP.NET Web API.
[HttpGet] public IHttpActionResult GetDetails([FromBody] RetrieveDetails eDetails) {}以下是课程
public class RetrieveDetails { public string name{ get; set; } public string Type { get; set; } }当我尝试从Fiddler调用 GetDetails EDetails 始终为空.
When I try to call GetDetails from Fiddler eDetails is always null.
localhost:101222/api/emailservice/GetDetails?name = testname& Type = testtype
我尝试了不同的方法,但该值始终为null.如果我将[HttpGet]更改为[HttpPost]并添加请求主体,则其工作正常.但是我需要获取方法.
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.
推荐答案如果您要在GET中传递URL值,是否需要[FromBody].如果要在查询字符串中传递值,则应使用[FromUri].
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.
> docs.microsoft/zh-cn/aspnet/web-api/overview/formats-and-model-binding/parameter-binding-in-aspnet-web-api
更多推荐
如何将参数传递给asp.net Web API get方法?
发布评论