Question

My error handling collects (some manually, some automatically) the errors produced during controller execution. Then I have a partial view which renders out the error messages. I store the error messages in ViewData (and transfer them to TempData if I respond in a RedirectResult).

The problem is: if a child action causes an error it will not get displayed, as they (at least the ones further down the page) are executed AFTER the partial view is rendered.

Right now the only, somewhat desperate idea I have is to render the messages into javascript at the bottom of the layout page, and have that javascript update the error display boxes. But it smells bad, I shouldn't need client-side code for this.

Is there a way to have a partial view "lazy rendered", after everything else?

Was it helpful?

Solution

You could try to use Html.Action and store the result in a variable for each of your child action.

And when you are done, you can call your Html.RenderPartial for your "error panel".

@{
    var result = Html.Action("ChildAction"); 
}

@Html.Partial("ErrorMessages")

@result

And then you resume with your regular layout by placing your variables instead of calling for the action.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top