_Layout.cshtml 主母版
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" > <html xmlns= "http://www.w3.org/1999/xhtml" > <head> <meta http-equiv= "Content-Type" content= "text/html; charset=utf-8" /> <title>@(ViewBag.Title == null ? "网站默认标题" : ViewBag.Title)</title> <meta name= "Keywords" content= "@(ViewBag.Keywords == null ? " 网站默认关键字 " : ViewBag.Keywords)" /> <meta name= "Description" content= "@(ViewBag.Description == null ? " 网站默认关键字 " : ViewBag.Description)" /> <link href= "@Url.Content(" ~/Content/Css/Product.css ")" rel= "stylesheet" type= "text/css" /> <link href= "@Url.Content(" ~/Scripts/Common/Common.css ")" rel= "stylesheet" type= "text/css" /> <script type= "text/javascript" src= "@Url.Content(" ~/Scripts/jquery-1.6.2.min.js ")" ></script> @RenderSection( "Head" , required: false ) </head> <body oncontextmenu=self. event .returnValue= false onselectstart= "return false" > @RenderBody() </body> </html> |
_Layout_Local.cshtml 子母版
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | @{ Layout = "~/Views/Shared/_Layout.cshtml" ; } @section Head{ @RenderSection( "Head" , required: false ) <script type= "text/javascript" src= "@Url.Content(" ~/App_Themes/Scripts/Jquery/plugin/jquery.artDialog/artDialog.js?skin=icons ")" ></script> } @Html.Partial( "~/Views/Shared/_Web_Top.cshtml" ) <div class = "top_ad" > <a href= "/Activity/201206/index.html" target= "_blank" ><img src= "/Content/testimg/ad_201206.jpg" alt= "" title= "" width= "960" height= "121" /></a> </div> <div class = "head" > <div class = "head_left" > <a href= "/" > <img src= "/Content/images/logo.png" width= "192" height= "71" /></a></div> <div class = "head_right" > <li> <img src= "/Content/images/head_text_02.png" /></li> <li> <img src= "/Content/images/head_text_01.png" /></li> <li> <img src= "/Content/images/head_text_tel.png" /></li> </div> </div> <div class = "clear" > </div> @RenderBody() <div class = "clear" > </div> @Html.Partial( "~/Views/Shared/_Web_Bottom.cshtml" ) |
index.cshtml 内容页
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | @{ ViewBag.Title = "新标题" ; ViewBag.Description = "新注释" ; Layout = "~/Views/Shared/_Layout_Local.cshtml" ; } @section Head{ <link rel= "stylesheet" type= "text/css" href= "/Content/Activity/Mobile/style.css" /> <script type= "text/javascript" src= "/Content/Activity/Mobile/jscript.js" ></script> } <div id= "Content02" class = "content" style= "display:none;" > <img src= "/Content/Activity/Mobile/title.gif" /> <img src= "/Content/Activity/Mobile/banner.jpg" /> <div class = "Form" style= "height:250px;" > <ul> <li> <input name= "C_Phone" id= "C_Phone" type= "text" value= "请输入接收短信的手机号码" onclick= "if($(this).val()=='请输入接收短信的手机号码'){$(this).val('')}" class = "input" maxlength= "11" /></li> <li> <input name= "" type= "image" src= "/Content/Activity/Mobile/Submit.png" onclick= "return chktop2();" style= "float: left; margin-left: 20px;" /></li> </ul> </div> </div> |
来自:http://www.cnblogs.com/haiyabtx/archive/2012/06/12/2545821.html
ASP.NET Core MVC中一样可以嵌套,注意嵌套的顺序
1 | 另外ViewData的数据传递要注意<br>如果上层模板中有同名的,比如上层模板中定义过ViewData[ "title" ]=‘123’,下层模板或内容页面中又定义了ViewData[ "title" ]=‘456’,则仍然显示123,不会显示456,下层模板或页面中未在上层模板中重复定义的ViewData会传递到模板上显示!笔记! |
分类:
ASP.NET Core MVC
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?
· 如何调用 DeepSeek 的自然语言处理 API 接口并集成到在线客服系统