单击a 时,是否有更好的方法从一个 Razor 页面导航到不同的 Razor 页面button。我想在单击按钮时从 导航Index.cshtml到。Inventory.cshtml
以下是我管理的当前有效解决方案,但我不确定这是否是正确的方法。使用的参考:https ://www.jetbrains.com/dotnet/guide/tutorials/basics/razor-pages/
索引.cshtml
@page
@model IndexModel
@{
ViewData["Title"] = "Home page";
}
<!--Page redirect-->
<form method="post" asp-page="Index">
<button type="submit" class="btn btn-cta">View Inventory</button>
</form>
Run Code Online (Sandbox Code Playgroud)
索引.cshtml.cs
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
namespace TheInventory.Pages
{
public class IndexModel : PageModel
{
private readonly ILogger<IndexModel> _logger;
public IndexModel(ILogger<IndexModel> logger)
{
_logger = logger;
}
public void OnGet()
{
}
//Page redirect on button form submit
public IActionResult OnPost()
{
return RedirectToPage("Inventory");
} …Run Code Online (Sandbox Code Playgroud)