I am developing a site with Header, Main Menu, Body and Footer sections.
I am using a web page base layout _Layout.cshtml
where I use the RenderPartial()
method to render the Header, Main Menu and Footer. For the body, I am using the RenderBody()
method.
In _Layout.cshtml
I have the following code:
<body style="margin: 0">
<form name="FormStart" method="post" action="Start.aspx" id="FormStart">
<table cellspacing="0" cellpadding="0" width="100%" align="center" border="0">
<tr>
<td valign="top" width="1px"></td>
<td valign="top" align="center" width="972" bgcolor="#FFFFFF">
<table id="Table1" cellspacing="0" cellpadding="0" width="972" border="0" bordercolor="yellow">
<!-- HEADER -->
@{Html.RenderPartial("_Header");}
<!-- MAIN MENU -->
@{Html.RenderPartial("_Menu");}
<!-- CONTENT -->
@RenderBody()
</table>
<br />
<!-- FOOTER -->
@{Html.RenderPartial("_Footer");}
</td>
</tr>
</table>
</form>
</body>
On the other hand, I created a very simple view with the following code
@{
ViewBag.Title = "Page";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h3>You just clicked </h3><h1>NATURAL ALOE SECTION</h1>
The thing is, that the content of this simple view is displayed at the very top of the page, whereas the rest is on the bottom. Instead of displaying HEADER-MAINMENU-my site-FOOTER it displays it in the order of my site-HEADER-MAINMENU-FOOTER.
I am quite new with MVC all around; I have been reading here about the possibility of using RenderSection instead of RenderPartial in my main Layout site, but could this be the reason while it is displaying this way? Probably I am way off base, any advice is much appreciated.
Thanks in advance.
This might be happening because you render the header, menu and body inside a <table>
. At least the body seems to be missing the row and cell tags (<tr><td>...</td></tr>
). Therefore there are no rows and cells in your table which can lead to all sorts of rendering problems.
It would probably help if you didn't render into a table and use CSS for layout purposes instead.