Custom 404 page in ASP.NET core 2.1 (Razor Pages)?
So I was following the introduction tutorial found here: https://docs.microsoft.com/en-us/aspnet/core/tutorials/razor-pages/razor-pages-start?view=aspnetcore-2.1
At some point in the tutorial you want to edit the EditModel page model which will then accept a URL of the form /Movies/Edit/{id}
Now I noticed that if I enter a non-existing id then the page is completely blank. The response is a 404 (as expected) but I can't seem to change the page. The relevant code is this:
public async Task<IActionResult> OnGetAsync(int? id) { if (id == null) { return NotFound(); } Movie = await _context.Movie.FirstOrDefaultAsync(m => m.ID == id); if (Movie == null) { return NotFound(); } return Page(); }
When I debug this I find that NotFound() only returns a NotFoundResult with StatusCode set to 404..... that's it.
So how do I return a custom 404 page instead?
0 comments:
Post a Comment