mirror of
https://github.com/dotnetcore/Util.git
synced 2026-10-29 03:26:31 +08:00
24 lines
860 B
C#
24 lines
860 B
C#
using System.Linq;
|
|
using Microsoft.AspNetCore.Mvc.ApplicationModels;
|
|
|
|
namespace Util.Samples.RazorPageExtensions {
|
|
/// <summary>
|
|
/// 视图页面路由约定,将页面路由添加view前缀
|
|
/// </summary>
|
|
public class ViewPageRouteConvention : IPageRouteModelConvention {
|
|
/// <summary>
|
|
/// 修改路由
|
|
/// </summary>
|
|
public void Apply( PageRouteModel model ) {
|
|
foreach( var selector in model.Selectors.ToList() ) {
|
|
var template = selector.AttributeRouteModel.Template;
|
|
if( string.IsNullOrWhiteSpace( template ) )
|
|
continue;
|
|
if( template.ToLower() == "index" )
|
|
continue;
|
|
selector.AttributeRouteModel.Template = $"view/{selector.AttributeRouteModel.Template}";
|
|
}
|
|
}
|
|
}
|
|
}
|