TemplateViewLocationExpander.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132
  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/BsServer/{1}/{0}.cshtml",
  17. "/Areas/Admin/Views/MainServer/{1}/{0}.cshtml",
  18. "/Areas/Admin/Views/JobServer/{1}/{0}.cshtml",
  19. "/Areas/Admin/Views/CashServer/{1}/{0}.cshtml",
  20. "/Areas/Admin/Views/SpServer/{1}/{0}.cshtml",
  21. "/Areas/Admin/Views/OperateServer/{1}/{0}.cshtml",
  22. };
  23. return locations.Union(viewLocations);
  24. }
  25. public void PopulateValues(ViewLocationExpanderContext context)
  26. {
  27. context.Values["template"] = context.ActionContext.RouteData.Values["Template"]?.ToString() ?? "Default";
  28. }
  29. }
  30. }