Sieve
Sieve copied to clipboard
SieveModel.Page not bound when using Razor Pages
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.