[英]how to pass parameters to asp.net web api get method?
Following is my get method in ASP.NET Web API. 以下是我在ASP.NET Web API中的get方法。
[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. 当我尝试从Fiddler调用
GetDetails
, eDetails
始终为null。
http://localhost:101222/api/emailservice/GetDetails?name=testname&Type=testtype http:// localhost:101222 / api / emailservice / GetDetails?name = testname&Type = testtype
I tried different methods but the value is always null. 我尝试了其他方法,但该值始终为null。 If I change [HttpGet] to [HttpPost] and add the request body its working fine.
如果我将[HttpGet]更改为[HttpPost]并添加请求主体,则其工作正常。 But I need get method.
但是我需要获取方法。
Do you need [FromBody] there if you are passing values in URL for GET. 如果要在GET的URL中传递值,是否需要[FromBody]。 You should be using [FromUri] if you are passing values in querystring.
如果要在查询字符串中传递值,则应使用[FromUri]。
https://docs.microsoft.com/en-us/aspnet/web-api/overview/formats-and-model-binding/parameter-binding-in-aspnet-web-api https://docs.microsoft.com/zh-cn/aspnet/web-api/overview/formats-and-model-binding/parameter-binding-in-aspnet-web-api
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.