page parameter in ArchiveModel.OnGet is always null
See original GitHub issueThe pagination does not work in a blog generated with Piranha.blog.razor because the page parameter is always null. With razor page, “page” is a route value set with the path to the page therefore the binding tries to bind the string “/Archive” instead of the query string parameter “3”.
There is at least 2 possible way to fix this
- add the attribute “[FromQuery]” before the page parameter:
public async Task OnGet(Guid id, int? year = null, int? month = null, [FromQuery] int? page = null, Guid? category = null, Guid? tag = null)
- rename the parameter to something else (pagenum ?) in the signature of the method and in the
IntegratedMiddleware
.
I notice that ArchiveRouter
set to the querystring both page and pagenum.
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Parameter value in Razor named page handler is null
I'm using Razor Pages in an ASP.NET MVC web application (.NET 7). In a Razor page, I added a named page handler next...
Read more >Model is always null on Razor page - Microsoft Q&A
hello All, I have the following code on my cshtml page: @if (Model!=null && Model.EmergencyInfos!=null && Model.EmergencyInfos.ToList().
Read more >[Solved] MVC id Value always null
The id is always coming null because you may not be using properly to assign the id. First of all the parameter you...
Read more >Optional Parameters in Razor Pages Routing
Parameters provide a way of passing arbitrary data to a page via the URL. Optional parameters allow URLs to matched to routes even...
Read more >RequestParameter always null
I'm trying to get request parameters to work... I access the unsubscribe.xhtml page below with the url: localhost:8080/EmailGather2/unsubscribe.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I ran into this problem recently with the last stable Nuget Package of piranha (8.42 I think). I also noticed that the problem is fixed on the Roadmap but while that’s not released or for people who can’t upgrade right away I just wanted to leave the temporary fix suggested by @ikhwanhayat here:
The model on the page template must be replaced with that as well of course, and the whole thing can be removed once version 9 is released
I’m new to Piranha and still getting the hang of things. Should I override the ArchivePage in my own project? I am referring to this file https://github.com/PiranhaCMS/piranha.core/blob/master/core/Piranha.AspNetCore/Models/ArchivePage.cs
Seems that things work if I replace the parameter “page” with “pagenum” instead.