using System; using System.Collections.Generic; using System.Linq; using Microsoft.AspNetCore.Mvc.Razor; namespace MySystem { public class TemplateViewLocationExpander : IViewLocationExpander { public IEnumerable ExpandViewLocations(ViewLocationExpanderContext context, IEnumerable viewLocations) { /// /// view文件路径 /// /// string[] locations = { "/Areas/Admin/Views/Admin/{1}/{0}.cshtml", "/Areas/Admin/Views/Base/{1}/{0}.cshtml", }; return locations.Union(viewLocations); } public void PopulateValues(ViewLocationExpanderContext context) { context.Values["template"] = context.ActionContext.RouteData.Values["Template"]?.ToString() ?? "Default"; } } }