I have an application which is built using both client side routing using react and server side routing using MapRazorPages. I need to map tasks/*
to a specific view and map everything to razor pages. I’m completely new to dotnet so I don’t really know what I’m doing but so far as I can tell I should be able to do something like this:
~/Startup.cs:
app.UseEndpoints(endpoints => { endpoints.MapRazorPages(); endpoints.MapControllerRoute("tasks", "{controller=Tasks}/{action=Index}/{id?}"); });
~/Controllers/TasksController.cs:
using Microsoft.AspNetCore.Mvc; namespace Web.API.Controllers.UI { public class TasksController : Controller { public IActionResult Index() { return View("../../Pages/Tasks"); } } }
But that returns an empty response and I’m guessing also wouldn’t work on anything other than
tasks/
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
Here is a demo:
TasksController:
public class TasksController : Controller { public IActionResult Index() { return RedirectToPage("/Tasks/Tasks"); } }
Pages/Tasks/Tasks.cshtml:
@page @model RazorPageDemo.Pages.Tasks.TasksModel @{ } <h1>Tasks-Razor Page!</h1>
result:

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0