Asp.Net MVC 3 - @Html.Action won't render/return any HTML

Steve Owen picture Steve Owen · Dec 10, 2010 · Viewed 16.4k times · Source

I've been moving a fairly new project from ViewPages to Razor today, and all seems to be going well. Except I'm trying to use Html.Action to render a user control and it won't render anything.

So I have a Shared/_Layout.cshtml file which is referenced in Home/Index.cshtml

Index.cshtml has the following:

<article>

@Html.Action("LatestBlogsMainPanelWidget", "Blogs")

...

</article>

I've put traps in the BlogsController, so I know that's being requested. I also know that a model is being returned, that the LatestBlogsMainPanelWidget is being found by the view engine, and even some dummy Razor syntax code is being run: @{ var s = "hello"; }

but the plain html in this file isn't making it to the browser. I've tried other (previously working) partials too and they won't appear either (view source on the page confirms it's not there).

I've also tried substituting for @{ Html.RenderAction(...); } without success. HTML either side of the @Html.Action is appearing, so I know Index.cshtml is displaying properly.

Even more strangely the _Layout file also has Html.Action commands and they do appear fine.

I'm really not sure what else to check, or how to confirm that the pipeline is getting the HTML. Can anyone help at all?

Thanks!

Answer

Schneider picture Schneider · Jan 21, 2011

Put a Layout = null on the partial view and it will work fine.