博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ASP.NET MVC中的嵌套布局页
阅读量:6892 次
发布时间:2019-06-27

本文共 1858 字,大约阅读时间需要 6 分钟。

在WEB窗体模式中,用惯了母版页,并且常有母版页嵌套的情况。

而在MVC模式下,对应母版页的,称作为布局页。默认的布局页为 ~/Views/Shared/_Layout.cshtml。默认每个页面都会嵌于其中,因为在~/Views/_ViewStart.cshtml里已经写好:

@{    Layout = "~/Views/Shared/_Layout.cshtml";}
当然,这个应该可以改的,但一般没有必要。我的做法是,将_Layout.cshtml作为基本母版页,然后再在上面衍生出各种子母版页。以下分别是_Layout.cshtml和某一子布局页(_SingleContent_Layout.cshtml)的代码:

_Layout.cshtml

@using common = www.AppCode.Common;    
@common.GetTitle(ViewBag.IndependentTitle,ViewBag.Title) @Styles.Render("~/Content/css") @Scripts.Render("~/bundles/modernizr")
@RenderSection("header", required: false)
@{Html.RenderAction("LoginInfo", "Partial");}
@{Html.RenderAction("Navi" , "Partial" , new { parentController = ViewContext.RouteData.Values["controller"].ToString() });}
@RenderBody()
@Scripts.Render("~/bundles/jquery182")
@RenderSection("scripts", required: false)
子母版页_SingleContent_Layout.cshtml

@{    Layout = "~/Views/Shared/_Layout.cshtml";}@section header{    @Styles.Render("~/Content/SingleContent")	@* 这是本子布局页的子页插入内容的入口,注意到没?它写在本子布局页插入母版页的入口处*@    @RenderSection("header", required: false)}@section Scripts {    @RenderSection("scripts", required: false)}
@RenderBody()
内容页index.cshtml

@{    ViewBag.Title = "Service";    Layout = "~/Views/Shared/_SingleContent_Layout.cshtml";}

服务条款

参考文章:

转载于:https://www.cnblogs.com/leftfist/p/4257975.html

你可能感兴趣的文章
openssl C语言编码实现rsa加密
查看>>
视频稳像
查看>>
VisualSVN-5.1.4补丁原创发布
查看>>
第三十三课:jQuery Deferred详解1
查看>>
UILable / UITextField / UIButton
查看>>
ti processor sdk linux am335x evm Makefile hacking
查看>>
shell脚本的桩
查看>>
perl函数指针
查看>>
Shell脚本调试技术
查看>>
cortex 内核简介
查看>>
字符串相似度算法 递归与动态规划求解分析
查看>>
Maven之setting.xml配置文件详解
查看>>
Docker Run 命令打包H5及其他后台应用
查看>>
POJ 3096:Surprising Strings
查看>>
python流程控制
查看>>
[scikit-learn] 特征二值化
查看>>
Laya播放unity特效
查看>>
hdu1025(nlon(n)最长上升子序列)
查看>>
监控文件事件inotify
查看>>
将Linux文件清空的几种方法
查看>>