I have DownloadController.cs
to Controllers/DownloadController
with the following method:
public async Task<ActionResult> DownloadFile(string key)
{
return File(...);
}
Also, in my Startup.cs
I have configured the following endpoints:
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "default".
pattern: "{controller}/{action}");
endpoints.MapControllers();
endpoints.MapBlazorHub();
endpoints.MapFallbackToPage("/_Host");
});
So how in a Blazor view can I navigate to the controller action? I was looking for something similar to this:
@Html.ActionLink(...);
Blazor applications are component-based. Blazor components can be used in existing ASP.NET MVC applications.
You can redirect to a page in Blazor using the Navigation Manager's NavigateTo method. In the following code snippet, it will redirect to the home page when this page gets loaded. Similarly, you can call NavigateTo() method from NavigationManager class anywhere to redirect to another page.
This should do:
@page "/MvcLinkExample"
@inject NavigationManager NavigationManager
<button @onclick="NavigateToMvcPage">MVC Link</button>
@code {
private void NavigateToMvcPage()
{
NavigationManager.NavigateTo("controllername/actionname/10", true);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With