TemplateViewLocationExpander.cs 926 B

1234567891011121314151617181920212223242526
  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. };
  17. return locations.Union(viewLocations);
  18. }
  19. public void PopulateValues(ViewLocationExpanderContext context)
  20. {
  21. context.Values["template"] = context.ActionContext.RouteData.Values["Template"]?.ToString() ?? "Default";
  22. }
  23. }
  24. }