ASP.NET Core bind query parameter with different name

Petr Kostelanský | 6 December 2017
If you have model with different name than query string you can simply use attribute to handle it

If you need bind query parameter to model that has different name of properties you can do that like this:

public class MyModel
{
    [FromQuery(name = "page_size")]
    public int PageSize { get; set; }

    [FromQuery(name = "page")]
    public int PageNumber { get; set; }
}

You don't have to create model binder for this purpose.

You can use FromQuery attribute from Microsoft.AspNetCore.Mvc.Core library.

Loading ads...