TemplateViewLocationExpander.cs 988 B

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