Zoeken…


Invoering

In ASP.NET MVC, worden de standpunten geplaatst standaard in de Views map. Soms wilt u deze locaties wijzigen en de weergaven ergens anders opslaan.

Maak een View Location Expander

Om de weergavelocatie te kunnen wijzigen, moet u de IViewLocationExpander implementeren. De methode ExpandViewLocations retourneert een IEnumerable<string> met de verschillende locaties waarnaar moet worden gezocht

public class MyViewLocationExpander : IViewLocationExpander
{
    public IEnumerable<string> ExpandViewLocations(ViewLocationExpanderContext context, IEnumerable<string> viewLocations)
    {
        yield return "/CustomViewFolder/{1}/{0}.cshtml";
        yield return "/SharedFolder/{0}.cshtml";
    }

    public void PopulateValues(ViewLocationExpanderContext context)
    {            
    }
}

Registreer de View Location Expander

U moet nu de Expander registreren, zodat deze door de Razor View Engine kan worden gebruikt. Voeg dit gewoon toe in de ConfigureServices van uw Startup klasse.

public void ConfigureServices(IServiceCollection services)
{
    services.Configure<RazorViewEngineOptions>(options => {
        options.ViewLocationExpanders.Add(new MyViewLocationExpander());
    });
}


Modified text is an extract of the original Stack Overflow Documentation
Licentie onder CC BY-SA 3.0
Niet aangesloten bij Stack Overflow