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!
Try this:
@{Html.RenderAction("LatestBlogsMainPanelWidget", "Blogs");}
The brain is a funny thing, and despite spending several hours on this yesterday, it took my dog waking me up in the middle of the night for a wee for my subconscious to stumble upon the answer.
If this had anyone else stumped, I'm not surprised. I hadn't mentioned because it hadn't dawned on me that I was using a partial-level caching system similar to one designed by Steve Sanderson. It suddenly struck me that this could be the cause, since to the best of my knowledge Razor pages go through far less pipeline processing than WebForm pages. The caching filter is probably not doing what it needs to do, or at the right time.
I've confirmed that commenting out the OutputCache filter on the Actions in question has fixed the problem.
I've no idea if this issue is true of the page-level caching as it's not something I find useful.
While searching solutions for this issue, I have find out three measure issues for not proper rendering of Html.Action and Html.RenderAction. Please verify have you done below things properly or not.
I hope by applying above all steps you can solve your issues.
Put a Layout = null on the partial view and it will work fine.