mvcdonutcaching icon indicating copy to clipboard operation
mvcdonutcaching copied to clipboard

excluding child action of a child action failes

Open mahdi87gh opened this issue 8 years ago • 13 comments

Hi I have a child action for creating my footer which loads data from database. And I am loading it like this in my Layout.chtml

@Html.Action("CreateFooter", "Home", true)

In CreateFooter action I call another child action for displaying page visit status which shouldn't be cached and needs to display fresh data. So in my CreateFooter.chtml

@Html.Action("GetStatus", "VisitCounter", new { Address = "PV-Home -> Index" },true)

But things in my footer gets messed up. some part of footer which is right after this line of code, repeats before whole footer!! If i change it to this line

@Html.Action("GetStatus", "VisitCounter", new { Address = "PV-Home -> Index" })

Nothing gets messed up but the visit status data wo'nt be fresh anymore.

In Home controller , CreateFooter has dounut attribute In VisitCounter controller , GetStatus has'nt dounut attribute

Please kindly help me.

mahdi87gh avatar Sep 21 '15 10:09 mahdi87gh

Can you provide me a simple MVC demonstrating the issue ?

moonpyk avatar Sep 21 '15 11:09 moonpyk

ok here is one example if you take a good look, in footer we should have two lines of "some other information about copyrights" but in second page load which is when the page is cached, we have 4 lines. https://drive.google.com/file/d/0B3YNJ8ZQzEClY3pmekxMeUVnN28/view?usp=sharing

mahdi87gh avatar Sep 21 '15 11:09 mahdi87gh

And I found out the second child action gets called just once! which should display fresh data everytime but it won't. Thanks

mahdi87gh avatar Sep 21 '15 11:09 mahdi87gh

Are you doing any of this in an actionfilter?

If so, I had a similar problem and discovered it's because the actionfilter was being called twice, if it is on an action which calls a child action. You can avoid that by checking filterContext.IsChildAction.

migig avatar Sep 24 '15 18:09 migig

Thanks man, But no I'm not. If you download the sample project you'll see.

mahdi87gh avatar Sep 25 '15 16:09 mahdi87gh

@mahdi87gh From your description it sounds like what I posted is correct. You need to somehow check for IsChildAction, and return if that is the case, else you will get two calls to the child action. See here.

migig avatar Sep 25 '15 16:09 migig

Dear @migig As I mentioned before, I'm not getting two calls at all, and I'm not using any action filter. You can see it for yourself in the sample project. Thanks anyway

mahdi87gh avatar Sep 26 '15 05:09 mahdi87gh

@mahdi87gh Your post implied that you are getting two calls, because you said that the markup is repeated. Maybe put a breakpoint in the innermost child action and double check?

migig avatar Sep 26 '15 06:09 migig

@migig I did that (putting breakpoints on every action) before and NO I'm not getting two calls!!! and markup is repeated that's why I posted here!

mahdi87gh avatar Sep 26 '15 07:09 mahdi87gh

That's weird... :frowning: Try StackOverflow....

migig avatar Sep 26 '15 07:09 migig

@mahdi87gh See this

migig avatar Sep 26 '15 09:09 migig

@migig Thanks I did what i had to. I put database driven markup inside CreateFooter action and other markup to _layout.chtml

mahdi87gh avatar Sep 26 '15 13:09 mahdi87gh

Cool :sunglasses:

migig avatar Sep 26 '15 15:09 migig