1

Here is what i am trying

Layout

<!DOCTYPE html>
<html lang="en">
 <head>
  <title>WebApp Name</title>
  <meta charset="utf-8" />
 </head>
 <body>
  <div id="menuContainer">
   @{Html.RenderPartial("~/Views/CustomPartials/_MainMenuPartial.cshtml");} @*Works*@
   @*@{Html.RenderAction("GetMenuStructure", "Custom");}*@ @*Not working*@
  </div>
  <div>
   @RenderBody()
  </div>
 </body>
</html>

Controller and Action method

namespace Webappl.Controllers
{
 [Authorize]
 public class CustomController : Controller
 {
   [AllowAnonymous]
   [ChildActionOnly]
   public ActionResult GetMenuStructure()
   {
    return PartialView("~/Views/CustomPartials/_MainMenuPartial.cshtml");
   }
 }
}

_MainMenuPartial.cshtml

<ul id="ul_MainMenuStructure">
    <li><a href="#">Guest Pg1</a></li>
    <li><a href="#">Guest Pg2</a></li>
    <li><a href="#">Guest Pg3</a></li>
</ul>

The problem is

@{Html.RenderPartial("~/Views/CustomPartials/_MainMenuPartial.cshtml");}

Renders the contents of _MainMenuPartial.cshtml into the layout perfectly.

While

@{Html.RenderAction("GetMenuStructure", "Custom");}

Does nothing. No errors. No exceptions. Just blank. If i place a break-point at

return PartialView("~/Views/CustomPartials/_MainMenuPartial.cshtml");

The break-point is getting hit. I press F5 and it goes forward without any error/exceptions but menu structure does not get rendered in the layout. All I have is a blank

<div id="menuContainer">
</div>

in the final rendered page when I view it in the browser.

I need to do it through the action method for certain custom logic to be executed. Thats why a render partial is not sufficient.

I was not able to find similar behavior reported any where including stackoverflow. It could be bad binging/googling skills.

Some help will be so greatly appreciated. Banging my head on it for 3 days now.

Michael
  • 33
  • 1
  • 6
  • Humbly requesting some help with this. Im sure there are experts in StackOverflow who could help out with this. I tried the best to my novice abilities but could not find out why this is happening. Somebody please help !!! – Michael Dec 04 '13 at 05:37
  • Dear admin I am wondering if my question is visible to others. because its so unlike 'Stackoverflow' to not even have a single response to a question. Ive seen many other simpler and more complex questions been atleast commented on within hours of posting it. 10 Days and not even one response makes me wonder. Its a very relevant question too... – Michael Dec 09 '13 at 04:34
  • I'm having the exact same problem. Did you figure it out on your own? – David Mar 11 '14 at 23:34

1 Answers1

0

I simply changed

@Html.RenderAction("X", "Y")

To

@Html.Action("X", "Y")
Jon Rea
  • 9,337
  • 4
  • 32
  • 35