Reputation: 139
How can I pass object parameter to get method? I searched a lot , for example how to pass parameters to asp.net web api get method?
Here It is mentioned that we should use [FromUri] but I could not see [FromUri] in .NET Core 2
[HttpGet]
public IHttpActionResult GetDetails([FromUri] RetrieveDetails eDetails)
{}
following is the class
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; }
}
But FromUri can not be used in .NET Core 2
Upvotes: 3
Views: 8738
Reputation: 20106
Generally, we use POST
method to pass an complex type.But you could also do it using [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
Upvotes: 5