gpt4 book ai didi

asp.net-web-api - 如何将对象参数传递给 web api 中的 get 方法?

转载 作者:行者123 更新时间:2023-12-05 02:12:02 25 4
gpt4 key购买 nike

如何将对象参数传递给get方法?我搜索了很多,例如 how to pass parameters to asp.net web api get method?

这里提到我们应该使用 [FromUri] 但我在 .NET Core 2 中看不到 [FromUri]

[HttpGet]
public IHttpActionResult GetDetails([FromUri] RetrieveDetails eDetails)
{}

下面是类

public class RetrieveDetails
{
public string Name{ get; set; }
public string Type { get; set; }
public List<MoreDetails> MoreDetails { get; set; }
}

public class MoreDetails {
public string DetailName{ get; set; }
}

但是 FromUri 不能在 .NET Core 2 中使用

最佳答案

通常,我们使用POST 方法来传递复杂类型。但是您也可以使用[FromQuery] 来传递GET 方法。

行动:

[HttpGet("Test")]
public async Task<IActionResult> GetDetails([FromQuery]RetrieveDetails eDetails)

网址:

.../Test?eDetails.Name=hello&eDetails.Type=world&eDetails.MoreDetails[0].DetailName=size&eDetails.MoreDetails[1].DetailName=price

关于asp.net-web-api - 如何将对象参数传递给 web api 中的 get 方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56585461/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com