If you are in the viewmodel, you can just call Context.RedirectToRoute("YourRoute", new { Param1 = something })
.
If you want to redirect from a different place, the easiest way is to create INavigationService
interface and implement it to call the method on IDotvvmRequestContext
(which is already registered in the ASP.NET Core dependency injection container):
public interface INavigationService
{
void NavigateTo(string routeName, object routeParameters);
}
public class DotvvmNavigationService
{
private IDotvvmRequestContext context;
public DotvvmNavigationService(IDotvvmRequestContext context) {
this.context = context;
}
public void NavigateTo(string routeName, object routeParameters) {
this.context.RedirectToRoute(routeName, routeParameters);
}
}
Then, you can just register the implementation as a scoped dependency in Startup.cs
and you should be able to get it anywhere you need.
services.AddScoped<DotvvmNavigationService>();