1
我是一位經驗豐富的Web開發人員,他一直在做項目管理而不是開發一年,所以我試着跳回來學習Razor。到目前爲止,這是一個令人沮喪的失敗。Razor RenderSection不起作用
我在VS2012中創建一個新的空剃刀的網站,並創建下列文件:
_MainLayout.cshtml:
<!DOCTYPE html>
<html>
<head>
<title>Razor Test</title>
</head>
<body>
<div>@RenderBody()</div>
<div>@RenderSection("testSection")</div>
</body>
</html>
ContentPage1.cshtml:
@{
Layout = "_MainLayout.cshtml";
}
<div>This is the content on the Razor Test Page.</div>
和TestSection。 cshtml:
@{
Layout = "_MainLayout.cshtml";
}
@section TestSection {
<h1>this is test section</h1>
}
當我嘗試和運行這個頁面,我得到以下錯誤:
Section not defined: "TestSection".
而且知道發生了什麼事?這應該是我可以得到的那麼簡單。顯然它太簡單。
謝謝。我看過的例子都沒有說明這一點非常明確(或者我正在看部分視圖示例,但沒有認識到這一區別)。 – Klay 2013-03-01 15:10:44
似乎節名稱和RenderSection值區分大小寫。 – Aaron 2014-05-11 03:29:48