Я пытаюсь загрузить области из пользовательского каталога, указав абсолютный путь (C: / WebApplication7 / MS / {2} / Views / {1} / {0} .cs html) . Я попытался указать AreaLocationFormats в Startup.cs и реализовать IViewLocationExpander . Оба из них работают нормально, когда я даю относительный путь (/MS/-1992/seals_look2-1/010*.*, но мне нужно загрузить представление, предоставив Точный путь к каталогу, так как мои представления будут присутствовать в отдельном каталоге. Возможно ли это каким-то образом?
services.AddControllersWithViews()
.AddRazorOptions(options =>
{
options.AreaViewLocationFormats.Add(@"/MS/{2}/Views/{1}/{0}.cshtml");
});
services.AddControllersWithViews()
.AddRazorOptions(options =>
{
options.ViewLocationExpanders.Add(new ViewLocationExpander());
});
public class ViewLocationExpander : IViewLocationExpander
{
public IEnumerable<string> ExpandViewLocations(ViewLocationExpanderContext context, IEnumerable<string> viewLocations)
{
//{2} is area, {1} is controller,{0} is the action
string[] locations = new string[] { "/MS/{2}/Views/{1}/{0}.cshtml" };
return locations.Union(viewLocations); //Add mvc default locations after ours
}
public void PopulateValues(ViewLocationExpanderContext context)
{
context.Values["customviewlocation"] = nameof(ViewLocationExpander);
}
}