Ok, im probably doing this wrong... But in my main _Layout I have this:
<div id="navigation">
@RenderSection("Navigation")
</div>
which points to this in my Index.cshtml view:
@section Navigation{
<-- Need this to point to Views/Shared/Navigation.cshtml -->
}
But I don't want to have a huge file with all my code in it, so I need to know how to point to a file called "Navigation.cshtml" inside of this section - basically so I have all my sections in separate, independent files.
I tried just doing @RenderPage("Navigation.cshtml") in the _Layout instead of @RenderSection, and that gives errors.
--EDIT--
If I add this instead of @RenderSection()
<div id="navigation">
= @RenderPage("~Views/Shared/Navigation.cshtml")
</div>
I get this:
The file "~/Views/Shared/~Views/Shared/Navigation.cshtml" could not be rendered, because it does not exist or is not a valid page.
--EDIT--
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>
Try with full path of view or you can use
Html.Partial()
or@Html.RenderPartial()
:Html.Partial():
Html.RenderPartial():
Try just to render a page "Views/Shared/Navigation.cshtml" as a partial view like this:
If you want to keep the
@RenderSection("Navigation")
in your_Layout
you can try below code in your view.OR you can change the
_Layout
as below.