爱上MVC~在Views的多级文件夹~续~分部页的支持

回到目录

之前写的一篇文章,主要针对View视图,它可以放在N级目录下,不必须非要在views/controller/action这种关系了,而在程序运行过程中,发现分页视图对本功能并不支持,原因很简单,在RazorViewEngine有不同的属于来修饰这两个东西,对于View的查找,通过ViewLocationFormats来定义,而分部视图的查找通过PartialViewLocationFormats来定义,它们定义了视图的查询范围,如~/Views/LindAdmin/{1}/{0}.cshtml就可以表示在Views下面的LindAdmin下的目录。

对于分部页的多级目录结构

  /// <summary>
/// 后台路由
/// </summary>
public class admin_routing : RazorViewEngine
{
public admin_routing()
{
//视图位置
ViewLocationFormats = new[]
{
"~/Views/{1}/{0}.cshtml",
"~/Views/LindAdmin/{1}/{0}.cshtml"//自定义汽车销售的试图
}; //分部视图位置
PartialViewLocationFormats = new[]
{
"~/Views/{1}/{0}.cshtml",
"~/Views/LindAdmin/{1}/{0}.cshtml"//自定义汽车销售的试图
};
} public override ViewEngineResult FindView(ControllerContext controllerContext, string viewName, string masterName, bool useCache)
{
return base.FindView(controllerContext, viewName, masterName, useCache);
} public override ViewEngineResult FindPartialView(ControllerContext controllerContext, string partialViewName, bool useCache)
{
return base.FindPartialView(controllerContext, partialViewName, useCache);
}
}

我们通过上面的代码看到了FindView和FindPartialView两个方法,它们就是在渲染视图时的查找方法,即你的action要去渲染哪个视图,我们可以把自己的逻辑重写在这两个

方法里!

看一下大家的通用后台项目,将后台的一些View都放到了LindAdmin里,而这也是为了打包考虑的,以后哪个具体的项目希望用后台,直接NUGET安装即可,边页面都不用做了,哈哈!

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAKYAAADMCAIAAAB2hU8cAAAKFUlEQVR4nO2dP4/bNhiH73Nk0BDgCsQe/QUK797v5nyA2zoXReEhQzoHMNAA18DjoWNSwEM1CSiy1EvaqdcpU5M0IZCihTsoVXXkS4qkKP7R+3sgHGhZpGg9JmWTr3lnAjDjLGxx2+12fZew5YPxhFS+3W6/+urrN3+87TYoz5BRyqUG3flu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ErkJggg==" alt="" />

回到目录

上一篇:SpringBoot整合系列-整合Swagger2


下一篇:IOT-SpringBoot-angular启动