ASP.NET Core MVC 는 IViewLocationExpander 를 통 해 보기 검색 경 로 를 확장 합 니 다.
지역 확장 기 를 만 듭 니 다.사실 저 는 여러 지역 이 필요 하지 않 습 니 다.저 는 현재 한 지역 에 여러 개의 폴 더 가 있어 서 제 보 기 를 저장 해 야 합 니 다.
그래서 저 는 IViewLocationExpander 를 실현 하여 확장 을 통 해 사용자 정의 보기 경로 규칙 을 추가 하면 다음 과 같은 코드 세 션 을 만 들 수 있 습 니 다.
public class MyViewLocationExpander : IViewLocationExpander
{
public IEnumerable<string> ExpandViewLocations(ViewLocationExpanderContext context, IEnumerable<string> viewLocations)
{
if (context.ControllerName != null && context.ControllerName.StartsWith("App"))
{
viewLocations = viewLocations.Concat(
new[] { $"/Areas/sysManage/Views/App/{context.ControllerName}/{context.ViewName}{RazorViewEngine.ViewExtension}"
});
return viewLocations;
}
if (context.AreaName != "sysManage") return viewLocations;
viewLocations = viewLocations.Concat(
new[] { $"/Areas/sysManage/Views/System/{context.ControllerName}/{context.ViewName}{RazorViewEngine.ViewExtension}"
});
return viewLocations;
}
public void PopulateValues(ViewLocationExpanderContext context)
{
}
}
Startup.Configure Services 에 등록 하기
public void ConfigureServices(IServiceCollection services)
{
services.Configure<RazorViewEngineOptions>(o => {
o.ViewLocationExpanders.Add(new MyViewLocationExpander());
});
services.AddMvc();
}
app.UseEndpoints(endpoints =>
{
endpoints.MapRazorPages();
endpoints.MapAreaControllerRoute(
name: "sysManage", "sysManage",
pattern: "{area:exists}/{controller=Home}/{action=Index}/{id?}");
});
최종 경로 가 가리 키 는 것 은 역시
/SysManage/Controller/Action
ASP.NET Core MVC 가 IView Location Expander 를 통 해 보기 검색 경 로 를 확장 하 는 것 에 관 한 이 글 은 여기까지 소개 되 었 습 니 다.더 많은 관련 ASP.NET Core MVC 확장 보기 검색 경로 내용 은 이전 글 을 검색 하거나 아래 의 관련 글 을 계속 찾 아 보 세 요.앞으로 도 많은 지원 바 랍 니 다!
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
부트스트랩 ASP.NET에서 설정하는 법1) _Layout.cshtml 內 link로 bootstrap 참조 2) Nuget 패키지에서 BootStrap 다운로드 3) 하단 부트스트랩 예제 사이트 참고해서 프로젝트 개발 참고 :...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.