cjk
cjk

Reputation: 46485

Action called twice

I have a @Html.Action() in my layout, and putting a breakpoint in the controller action behind this shows it is being called twice (one seems to be as part of the overall controller action returning my main View and the second seems to be on the @Renderbody() call).

This results in my partial view being returned from the action (depending on the user role) being shown twice, once in the right place in the layout (where the @Html.Action() call is and once within the rest of the page, just before where next @Html.Action() call is inside the main page being shown in the layout.

I assume it has something to do with @Renderbody() displaying all partial views returned from the controller but I have no idea.

Any pointers on if this is true, and if so how can I show my menu without using an action?

Upvotes: 1

Views: 1834

Answers (1)

markt
markt

Reputation: 193

I had a similar situation where I was calling an ActionResult using @Html.Action in order to render a partial view (after processing some data), however it kept repeating the layout twice. To fix it I had to change the ActionResult to a PartialViewResult, even though both were returning a partial view, the former seemed to treat it as if it were returning a view anyway...

Upvotes: 5

Related Questions