_ViewStart.cshtml注意事項

基本用法

_ViewStart.cshtml會首先被加載,使_Layout.cshtml被渲染爲模板頁,同時其他頁面也需要添加相應改變。

_ViewStart.cshtml頁面

@{
    Layout = "~/Areas/Adnn1n/Views/Shared/_Layout.cshtml";
}

_Layout.cshtml頁面(模板頁)

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>@ViewData["Title"] - NiuNan.Blog.UI</title>
    <link href="~/layui/css/layui.css" rel="stylesheet" />
</head>
<body>
        @RenderBody()
</body>
</html>

子頁

需要引入模板頁

@{ 
    Layout = "~/Areas/Adnn1n/Views/Shared/_Layout.cshtml";
}
<blockquote class="layui-elem-quote">後臺歡迎頁面</blockquote>

其他頁面

@{ 
    Layout = null;   //必須添加,否則會衝突,表示不引人模板頁
}
<!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>無標題文檔</title>
</head>
<body>
</body>

疑惑

frame標籤的src屬性可以不用加後綴

@{
    Layout = null;
}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>信息管理系統界面</title>
</head>
<frameset rows="88,*" cols="*" frameborder="no" border="0" framespacing="0">
    <frame src="/Adnn1n/Login/Top" name="topFrame" scrolling="No" noresize="noresize" id="topFrame" title="topFrame" />
    <frameset cols="187,*" frameborder="no" border="0" framespacing="0">
        <frame src="/Adnn1n/Login/Left" name="leftFrame" scrolling="No" noresize="noresize" id="leftFrame" title="leftFrame" />
        <frame src="/Adnn1n/Login/Welcome" name="rightFrame" id="rightFrame" title="rightFrame" />
    </frameset>
</frameset>
    @*爲什麼要在這裏添加body???*@
<noframes>
    <body>
    </body>
</noframes>

</html>

總結

邏輯思維不清晰,要多加練習,形成一套自己的學習體系。

發佈了16 篇原創文章 · 獲贊 49 · 訪問量 11萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章