实例:
(1)视图文件夹新建一个布局页

布局页代码:

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>@ViewBag.Title</title>
</head>
<body>
    <div style="background-color:cyan;width:100%;height:50px;">
        @RenderSection("Top")
    </div>
    <div style="background-color:palevioletred;width:100%;height:100px;">
        @RenderBody()
    </div>
    <div style="background-color:chartreuse;width:100%;height:50px;">
        @RenderSection("Foot")
    </div>
</body>
</html>

(2)添加视图视图时引用布局页
在这里插入图片描述
使用布局页:
在这里插入图片描述
(3)视图代码:

@{
    ViewBag.Title = "Fun2";
    Layout = "~/Views/02_LayoutPage.cshtml";/*引用布局页*/
}
@*填充内容*@
@section Top{ 头部}
fghj
@section Foot{ foot}

(4)执行效果
在这里插入图片描述

posted on 2019-05-11 12:04  豆皮没有豆  阅读(243)  评论(0)    收藏  举报