I am faced with a problem with ASP.NET MVC 3 with the Razor rendering engine (C#). I am using multiple Html.RenderAction() methods within a view and only the layout is rendered.
One important note before continuing: I can't copy any of the code because I do not have the intellectual property rights to do so. :(
Anyway, I noticed that if I used the following syntax @{ RenderSection("SectionName", true); } instead of @RenderSection("SectionName", true) there was a generic exception that simply says that it was unable to render the sections with a stack trace that seemed to say that there might be some asynchronous problem. Between, I am using synchronous controllers so maybe this is a lead, but I don't know much on synchronous/asynchronous controllers and when one should use them for certain situations.
To put everything in context, here is what I am trying to do in code/pseudo code/site structure...
~/View/Shared/_ViewStart.cshtml
(Selects a layout according to certain conditions.)
~/View/Shared/_Layout1.cshtml
<! doctype HTML>
<html>
<head>
<!-- some irrelevant content here... -->
</head>
<body>
<div id="page">
<div id="header">
@RenderSection("Header", true)
</div>
<div id="content">
<div id="main1">
@RenderSection("Table1", true)
@RenderSection("Table2", true)
</div>
<div id="main2">
@RenderSection("Content", true)
</div>
</div>
<div id ="footer">
@RenderSection("Footer", true)
</div>
</div>
</body>
</html>
~/View/Shared/_Layout2.cshtml
(another layout)
~/View/Controller1/Action1.cshtml
@section Header
{
@RenderPage("~/Views/Shared/Sections/Header")
}
@section Footer
{
@RenderPage("~/Views/Shared/Sections/Footer")
}
@section Table1
{
@{ RenderAction("Table1", "Table"); }
}
@section Table2
{
@{ RenderAction("Table2", "Table"); }
}
@section Content
{
@{ RenderAction("Action", "Content"); }
}
~/View/Controller1/Action2.cshtml
(similar to Action1.cshtml)
~/Utilities/ModelManager.cs
public abstract class ModelManager : Controller
{
//Some useful code for controllers here...
}
~/Controller/Controller1.cs
public class Controller1 : ModelManager
{
#region Get Methods
public ViewResult Action1()
{
return View();
}
public ViewResult Action2()
{
return View();
}
#endregion
#region Post Methods
public ViewResult Action1(FormCollection form)
{
return View();
}
public ViewResult Action2(FormCollection form)
{
return View();
}
#endregion
}
~/Controller/Controller2.cs
(another controller similar to Controller1)
~/Controller/Table.cs
(Only important thing to note is that the actions are returning PartialViewResult.)
~/Controller/Content.cs
(Only important thing to note is that the action is returning PartialViewResult.)
~/Model/Entities.edmx
(Generated with Entity Framework Wizard.)
* Edit *
The @Html.Action(...) worked, but I would really like to know why the @Html.RenderAction(...) didn't work. Any suggestions are welcome. :)