asp.net-core-mvc
기본보기 위치 변경
수색…
소개
ASP.NET MVC에서보기는 기본적으로 Views
폴더에 배치됩니다. 때로는이 위치를 변경하고보기를 다른 위치에 저장하려고합니다.
보기 위치 확장기 만들기
뷰 위치를 변경하려면 IViewLocationExpander
를 구현해야합니다. ExpandViewLocations
메서드는 검색 할 위치가 서로 다른 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)
{
}
}
보기 위치 확장기 등록
Razor View Engine에서 확장기를 사용하려면 Expander를 등록해야합니다. 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