I ran into a problem with ASP.NET MVC 3 with the Razor rendering engine (C #). I use several Html.RenderAction() methods in the view, and only the layout is displayed.
One important note before continuing: I cannot copy any code because I do not have intellectual property rights. :(
In any case, I noticed that if I used the following syntax @{ RenderSection("SectionName", true); } @{ RenderSection("SectionName", true); } instead of @RenderSection("SectionName", true) , there was a general exception, which simply says that he was unable to display sections with a stack trace, which seemed to have some asynchronous problems. In between, I use synchronous controllers, so maybe this is a leadership, but I know little about synchronous / asynchronous controllers and when they need to be used for certain situations.
To put everything in context, here is what I am trying to do in code / pseudo-code or site structure ...
~ / View / Shared / _ViewStart.cshtml
(Selects a layout according to certain conditions.)
~ / View / Shared / _Layout1.cshtml
<! doctype HTML> <html> <head> </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 {
~ / 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 *
@Html.Action(...) worked, but I would really like to know why @Html.RenderAction(...) did not work. Any suggestions are welcome. :)