Asp.Net MVC 3 - @ Html.Action will not display / return HTML

Today I transferred a fairly new project from ViewPages to Razor, and everything seems to be going well. Also, I'm trying to use Html.Action to render a user control and will not do anything.

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

Index.cshtml has the following:

<article> @Html.Action("LatestBlogsMainPanelWidget", "Blogs") ... </article> 

I put traps in BlogController, so I know that I'm being asked. I also know that the model returns that there is a view mechanism in the RecentBlogsMainPanelWidget file, and even some dummy Razor syntax code is executed: @ {var s = "hello"; }

but the simple html in this file does not get into the browser. I also tried other (previously working) partial ones, and they will not appear either (viewing the source on the page confirms this is not there).

I also tried replacing @ {Html.RenderAction (...); } unsuccessfully. HTML on both sides of @ Html.Action appears, so I know that Index.cshtml is displayed correctly.

Even stranger, the _Layout file also contains Html.Action commands, and they do look great.

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

Thanks!

+7
asp.net-mvc-3 razor renderaction partials
source share
4 answers

The brain is a funny thing, and despite the fact that he spent a few hours on it yesterday, my dog ​​woke me up in the middle of the night to be conscious, to stumble upon an answer.

If someone else was at a standstill, I am not surprised. I didn’t mention it because I didn’t understand that I was using a partial level caching system similar to the one developed by Steve Sanderson. Suddenly, it seemed to me that this could be the reason, since, as far as I know, Razor pages go through much less pipeline processing than WebForm pages. The cache filter probably does not do what it needs, or at the right time.

I have confirmed that commenting on the OutputCache filter in the Actions in question resolves the issue.

I don't know if this issue relates to page-level caching, as that is not what I find useful.

+1
source share

Place the layout = zero in a partial view and it will work fine.

+8
source share

Try the following:

@ {Html.RenderAction ("LatestBlogsMainPanelWidget", "Blogs");}

+6
source share

When searching for solutions to this problem, I found three measurement problems for the incorrect transmission of Html.Action and Html.RenderAction. Check if you did something below correctly or not.

  • In your PartialView or View, you defined @ {Layout = null;} .
  • Use return PartialView instead of View .
  • Decorate your action with the [ChildActionOnly] attributes.

Hopefully by applying above all the steps you can solve your problems.

+1
source share

All Articles