如何将参数传递给asp.net Web API get方法?

编程入门 行业动态 更新时间:2024-10-17 02:55:16
本文介绍了如何将参数传递给asp Web API get方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

以下是我在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方法?

本文发布于:2023-11-14 04:10:34,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1586177.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何将   参数   方法   API   net

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!