oliverbooth.dev/OliverBooth/Pages/Blog/List.cshtml.cs

38 lines
1.1 KiB
C#
Raw Normal View History

2024-07-15 18:44:02 +00:00
using System.Web;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
namespace OliverBooth.Pages.Blog;
/// <summary>
/// Represents a class which defines the model for the <c>/blog/page/#</c> route.
/// </summary>
public class List : PageModel
{
/// <summary>
/// Gets the requested page number.
/// </summary>
/// <value>The requested page number.</value>
public int PageNumber { get; private set; }
2024-07-15 18:38:56 +00:00
public string[] Tag { get; private set; } = [];
/// <summary>
/// Handles the incoming GET request to the page.
/// </summary>
/// <param name="page">The requested page number, starting from 1.</param>
2024-07-15 18:38:56 +00:00
/// <param name="tag">The tag by which to filter results.</param>
/// <returns></returns>
2024-07-15 18:38:56 +00:00
public IActionResult OnGet([FromRoute(Name = "pageNumber")] int page = 1, [FromQuery(Name = "tag")] string? tag = null)
{
if (page < 2)
{
return RedirectToPage("Index");
}
PageNumber = page;
2024-07-15 18:44:02 +00:00
Tag = (tag?.Split('+').Select(HttpUtility.UrlDecode).ToArray() ?? [])!;
return Page();
}
}