标签:ble isnull oid return code text space ati values
PopulateValues():作为一种指定参数的方式存在,您的视图查找将根据每个请求而变化.由于您没有填充它,视图引擎使用先前请求中的缓存值.
public class ThemeViewLocationExpander : IViewLocationExpander { public IEnumerable<string> ExpandViewLocations(ViewLocationExpanderContext context, IEnumerable<string> viewLocations) { string theme = context.Values["theme"]; if (string.IsNullOrWhiteSpace(theme)) { theme = "default"; } string[] newLocation = { $"Views/{theme}/{{1}}/{{0}}.cshtml"}; return viewLocations.Union(newLocation); } public void PopulateValues(ViewLocationExpanderContext context) { context.Values["theme"] = context.ActionContext.HttpContext.Request.Query["theme"].ToString(); } }
//配置模版视图路径 services.Configure<RazorViewEngineOptions>(options => { options.ViewLocationExpanders.Add(new ThemeViewLocationExpander()); });
标签:ble isnull oid return code text space ati values
原文地址:https://www.cnblogs.com/fanfan-90/p/12716694.html