TemplateViewLocationExpander.cs 949 B

1234567891011121314151617181920212223242526272829
  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. "/Views/{1}/{0}.cshtml",
  19. };
  20. return locations.Union(viewLocations);
  21. }
  22. public void PopulateValues(ViewLocationExpanderContext context)
  23. {
  24. context.Values["template"] = context.ActionContext.RouteData.Values["Template"]?.ToString() ?? "Default";
  25. }
  26. }
  27. }