如何将对象参数传递给 get 方法?我搜索了很多,
例如如何将参数传递给asp.net web api get方法? https://stackoverflow.com/questions/45766147/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]
for GET
method.
Action:
[HttpGet("Test")]
public async Task<IActionResult> GetDetails([FromQuery]RetrieveDetails eDetails)
Url:
.../Test?eDetails.Name=hello&eDetails.Type=world&eDetails.MoreDetails[0].DetailName=size&eDetails.MoreDetails[1].DetailName=price
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)