aspnetcore/test/WebSites/RazorWebSite/Services/BackSlashExpander.cs

27 lines
913 B
C#

// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Generic;
using Microsoft.AspNetCore.Mvc.Razor;
using Microsoft.AspNetCore.Mvc.Rendering;
namespace RazorWebSite
{
public class ForwardSlashExpander : IViewLocationExpander
{
public void PopulateValues(ViewLocationExpanderContext context)
{
}
public virtual IEnumerable<string> ExpandViewLocations(ViewLocationExpanderContext context, IEnumerable<string> viewLocations)
{
if (context.ActionContext is ViewContext viewContext && (string)viewContext.ViewData["back-slash"] == "true")
{
return new[] { $@"Views\BackSlash\{context.ViewName}.cshtml" };
}
return viewLocations;
}
}
}