好吧,即时通讯可能这样做不对......但在我的主要_layout我有这样的:
<div id="navigation">
@RenderSection("Navigation")
</div>
它指向这在我Index.cshtml观点:
@section Navigation{
<-- Need this to point to Views/Shared/Navigation.cshtml -->
}
但我不希望有与我的所有代码一个巨大的文件,所以我需要知道如何指向一个名为“Navigation.cshtml”这一节里面的文件 - 基本上让我有我的所有部分在单独的,独立的文件。
我试着只是做@RenderPage(“Navigation.cshtml”)在_layout而不是@RenderSection,并给出错误。
- 编辑 -
如果我添加此代替@RenderSection()
<div id="navigation">
= @RenderPage("~Views/Shared/Navigation.cshtml")
</div>
我得到这个:
The file "~/Views/Shared/~Views/Shared/Navigation.cshtml" could not be rendered, because it does not exist or is not a valid page.
- 编辑 -
FULL _Layout.cshtml:
<!DOCTYPE html>
<html>
<head>
<title>@ViewBag.Title</title>
<link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />
<script src="@Url.Content("~/Scripts/jquery-1.7.1.min.js")" type="text/javascript"> </script>
</head>
<body>
<div id="wrapper">
<div id="content">
<!-- BANNER -->
<div id="banner">
</div>
<!-- NAVIGATION -->
<div id="navigation">
@RenderPage("Navigation.cshtml")
</div>
<!-- MAIN DISPLAY -->
<div id="main">
@RenderBody()
</div>
<!-- FOOTER -->
<div id="footer">
</div>
</div>
</div>