Sieve icon indicating copy to clipboard operation
Sieve copied to clipboard

SieveModel.Page not bound when using Razor Pages

Open andreibsk opened this issue 6 years ago • 0 comments

When using an ASP.NET Core MVC controller with public IActionResult Index(SieveModel sieveModel) everything works as expected, however the analogue code using Razor Pages fails to bind the value of the Page property:

public class IndexModel : PageModel
{
    public void OnGet(SieveModel sieveModel)
    {
    }
}

Navigating to http://localhost:61688/?page=2&sorts=asdf&filters=asdf&pageSize=50 yields the following model:

{Sieve.Models.SieveModel}
    Filters: "asdf"
    Page: null
    PageSize: 50
    Sorts: "asdf"

As a workaround I've been using the [FromQuery] attribute on the parameter public void OnGet([FromQuery] SieveModel sieveModel) yielding the full model as expected:

{Sieve.Models.SieveModel}
    Filters: "asdf"
    Page: 2
    PageSize: 50
    Sorts: "asdf"

This could either be considered a bug, or an unavoidable behavior of using Razor Pages. If it's the the latter case, perhaps it should be documented.

andreibsk avatar Jun 13 '19 18:06 andreibsk