简体   繁体   English

如何将参数传递给ASP.NET Web API Get方法?

[英]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调用GetDetailseDetails始终为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.

相关问题 如何将jquery中的string []类型参数传递给asp.net Web API方法? - How to pass string[] type parameters from jquery to asp.net web api method? 如何在asp.net WEB API中传递多个querystring参数 - how to pass multiple querystring parameters in asp.net WEB API ASP.NET Core中如何将多个参数传递给一个get方法 - How to pass multiple parameters to a get method in ASP.NET Core ASP.NET Web API操作方法参数的依赖注入 - Dependency injection for ASP.NET Web API action method parameters 如何在ASP.NET中的Kendo Web方法数据源中传递参数? - How to pass parameters in kendo web method data source in asp.net? 如何将Json参数绑定到ASP.NET中的Web Api参数? - How to bind Json parameters to Web Api parameters in ASP.NET? 如何使用ASP.NET Core Web API向url地址传递三个参数 - How to pass three parameters to url address using ASP.NET Core Web API 如何从ASP.NET Web APi中的Body传递参数信息? - how to pass Parameters Info from the Body in ASP.NET Web APi? 将$ http.get()方法中的$ scope.object传递给asp.net web api - pass $scope.object in $http.get() method to asp.net web api 如何在asp.net Web API中调用具有多个参数的控制器方法? - How to call a controller method with multiple parameters in asp.net web api?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM