2

We can use [FromQuery(Name"param")] in a controller action to specify how the passed parameter will be used in the uri as in :

[HttpGet()]
public IActionResult GetPeople([FromQuery(Name="page")] int pageNumber, [FromQuery(Name="size")] int pageSize)
{
     //Do things
}

How to use that in the case of using a complex type such as PeoplePaginationParameters where :

public class PaginationParameters
{
    public int PageNumber { get; set;}
    public int PageSize { get; set;}
}

Is there any thing like :

[HttpGet()]
public IActionResult GetPeople([FromQuery(Name="page", Name="size")] PaginationParameters paginationParameters)
{
    //Do things
}

1 Answer 1

5

You can just use the [FromQuery(Name="parameterName")] on each property of the complex type :

public class PaginationParameters
{
    [FromQuery(Name = "page")]
     public int PageNumber { get; set;}
    [FromQuery(Name = "size")]
    public int PageSize { get; set;}
}
Sign up to request clarification or add additional context in comments.

1 Comment

Is there any other solution? You cannot use this if you are using a layered architecture and requests in a different project (you'd have to pull MVC dependency onto that project).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.