question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

page parameter in ArchiveModel.OnGet is always null

See original GitHub issue

The 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

  1. 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)
  2. 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:closed
  • Created 4 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
j-bbrcommented, Jan 15, 2021

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:

public class ArchivePageWithFixedPagination : ArchivePage<StandardArchive, Piranha.Models.PostInfo>
    {
        public ArchivePageWithFixedPagination(IApi api, IModelLoader loader) : base(api, loader) { }

        public override Task<IActionResult> OnGet(Guid id, int? year = null, int? month = null, int? pageNum = null, Guid? category = null, Guid? tag = null,
            bool draft = false) =>
            base.OnGet(id, year, month, pageNum, category, tag, draft);
    }

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

0reactions
ikhwanhayatcommented, Sep 12, 2020

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found