作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
如何将对象参数传递给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/
我是一名优秀的程序员,十分优秀!