IViewLocationExpander API
项目目录如下所示
创建区域扩展器,其实我并不需要多区域,我目前只需要达到一个区域中有多个文件夹进行存放我的视图.
所以我通过实现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.ConfigureServices 注册
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通过IViewLocationExpander扩展视图搜索路径的实现的文章就介绍到这了,更多相关ASP.NET Core MVC 扩展视图搜索路径内容请搜索站长技术以前的文章或继续浏览下面的相关文章希望大家以后多多支持站长技术!
这是学习TensorFlow过程中记录的一点笔记在此分享一下。 文章目录 TensorFlow简...
前言 如果你是或者你想成为一名合格的前端开发工作者,你必须知道JavaScript代码...
一般情况下,很少会用php去执行linux命令,不过特殊情况下,你也许会用到这些函...
提示:我提取了《xslt从入门到精通》中关于空格解释的核心部分,借以抛砖引玉,...
本文转载自微信公众号「DBA闲思杂想录」,作者潇湘隐者。转载本文请联系DBA闲思...
端点路由(Endpoint Routing)最早出现在ASP.NET Core2.2,在ASP.NET Core3.0提升...
当我们制作一个页面时,尤其是制作一个首页时,通常会设计一个可以链接到整个网...
需求:输入框中输入银行卡号(或其他)时,每4位自动加空格(如下图) 分析 方法...
在HTML编辑器发布过程中,会出现一些自动生成的HTML标签,或者在留言板程序应用...
1、为什么要进行数据库收缩? SQL Server 数据库采取预先分配空间的方法来建立数...