




















//添加Razor页面
builder.Services.AddRazorPages();
//使用路由,需在app.UseAntiforgery();之前添加
app.UseRouting();
//映射Razor页面
app.MapRazorPages();
Pages文件夹Pages文件夹中添加_ViewImports.cshtml文件@using Sample.Web
@namespace Sample.Web.Pages
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
Pages文件夹中添加Razor页面,命名Test,自动生成Test.cshtml和Test.cshtml.cs两个文件Test.cshtml文件示例如下:@page
@model TestModel
<h2>@Model.Id</h2>
Test.cshtml.cs文件示例如下:namespace Sample.Web.Pages;
public class TestModel : Microsoft.AspNetCore.Mvc.RazorPages.PageModel
{
public string Id { get; set; }
//路由:域名/test?id=123242
public async void OnGet(string id)
{
Id = id;
}
}
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。