TemplateViewLocationExpander.cs 908 B

12345678910111213141516171819202122232425262728
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using Microsoft.AspNetCore.Mvc.Razor;
  5. namespace MySystem
  6. {
  7. public class TemplateViewLocationExpander : IViewLocationExpander
  8. {
  9. public IEnumerable<string> ExpandViewLocations(ViewLocationExpanderContext context, IEnumerable<string> viewLocations)
  10. {
  11. /// <summary>
  12. /// view文件路径
  13. /// </summary>
  14. /// <value></value>
  15. string[] locations = {
  16. "/Areas/Admin/Views/Admin/{1}/{0}.cshtml",
  17. "/Areas/Admin/Views/Base/{1}/{0}.cshtml",
  18. };
  19. return locations.Union(viewLocations);
  20. }
  21. public void PopulateValues(ViewLocationExpanderContext context)
  22. {
  23. context.Values["template"] = context.ActionContext.RouteData.Values["Template"]?.ToString() ?? "Default";
  24. }
  25. }
  26. }