Mikhail Kriseev
Mikhail Kriseev

Reputation: 89

RazorPages How to pass GET parameters to OnGet?

I have a RazorPages application and it's index page has a list of items. I want this page to show only 50 elements of list and decide what items to show using GET parameter, for example if I pass ?page=2 to page it must display elements from 51 to 100

As I have found, I can handle this type of request in OnGet like that:

public void OnGet(int page)

But when I open page - the page parameter in OnGet is always 0 even if I pass '?page=2' or something like this

I tried also using string instead of int and always got "/Index"

What is the correct way to handle these parameters in OnGet?

Upvotes: 1

Views: 2458

Answers (1)

Serge
Serge

Reputation: 43959

Try to add in you page view

@page "{pageNum:int?}"

and model

public void OnGet(int? pageNum)

Upvotes: 2

Related Questions