无锡课外辅导,广告案例分析,林倩
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 扩展视图搜索路径内容请搜索移动技术网以前的文章或继续浏览下面的相关文章希望大家以后多多支持移动技术网!
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
Net Core Web Api项目与在NginX下发布的方法
asp.net core3.1 引用的元包dll版本兼容性问题解决方案
IdentityServer4实现.Net Core API接口权限认证(快速入门)
ASP.NET Core MVC通过IViewLocationExpander扩展视图搜索路径的实现
网友评论