खोज…


परिचय

ASP.NET MVC में, Views फ़ोल्डर में डिफ़ॉल्ट रूप से विचार रखे जाते हैं। कभी-कभी आप इस स्थान को बदलना चाहते हैं और विचारों को कहीं और संग्रहीत करते हैं।

एक स्थान का विस्तारक बनाएँ

दृश्य स्थान को बदलने में सक्षम होने के लिए, आपको IViewLocationExpander को लागू करने की IViewLocationExpanderExpandViewLocations विधि एक IEnumerable<string> अलग-अलग स्थानों से युक्त होती है, जहां खोज करने के लिए

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)
    {            
    }
}

स्थान का विस्तारक पंजीकृत करें

रेजर व्यू इंजन द्वारा उपयोग किए जाने के लिए अब आपको एक्सपैंडर को पंजीकृत करने की आवश्यकता है। बस इसे अपने Startup वर्ग के ConfigureServices में जोड़ें।

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
के तहत लाइसेंस प्राप्त है CC BY-SA 3.0
से संबद्ध नहीं है Stack Overflow