创建伪静态类
using Microsoft.AspNetCore.Mvc.ApplicationModels; using System.Text; namespace Micro.Web { public class HtmlExtensionPageRouteModelConvention : IPageRouteModelConvention { public void Apply(PageRouteModel model) { var selectorsCount = model.Selectors.Count; for (var i = 0; i < selectorsCount; ++i) { var attributeRouteModel = model.Selectors[i].AttributeRouteModel; if(attributeRouteModel!= null) { //添加之前 if (string.IsNullOrEmpty(attributeRouteModel.Template)) continue; //该规则是否禁止链接的生成,默认为生成(支持TagHelpers) asp-page="/Index" attributeRouteModel.SuppressLinkGeneration = true; //添加新的路由模板 model.Selectors.Add(new SelectorModel { AttributeRouteModel = new AttributeRouteModel { //Order 路由匹配顺序 //SuppressLinkGeneration = true, Template = $"{attributeRouteModel.Template}.html", } }); } } } } }
Program.cs 调用
builder.Services.AddRazorPages().AddRazorPagesOptions(options => options.Conventions.Add(new HtmlExtensionPageRouteModelConvention()));
标签:Core,attributeRouteModel,静态,Selectors,Template,var,new,Net,model From: https://www.cnblogs.com/microsoft-zh/p/17893623.html