tags:

views:

136

answers:

2

I ran into a small roadblock this morning with HandleError. Users are directed properly to the /Views/Shared/Error.aspx. This view uses a Master Page which also displays just fine. It also logs the particulars of the ViewData.Model.Exception in its Page_Load method. An acceptable use of codebehind in my opinion.

My problem is this: The page contains a strongly-typed Partial View that contains some of the user's input data. I would like to retain access to that data even after the exception occurs - so the user isn't doubly-penalized for our exception (being presented with an error message AND losing their form values).

Is there a way to accomplish this using HandleError or another reusable attribute?

A: 

The way I get around this problem is to use Ajax.BeginForm(){} and Render the user control that way your view is not refreshed and your input is not lost. If your error messages are strictly input restrictions then you can also use jquery.validate.js file can be found here http://randomactsofcoding.blogspot.com/2008/09/starting-with-jquery-validation-plug-in.html

Ayo
These are not input validation exceptions, they are actual application exceptions that were handled in my models or elsewhere (like a SQL error) but bubbled to the page so the user is aware an error occurred.
Peter J
A: 

The simplest solution would be the back-button, and it needs no code :-)

If you need a code-based solution, I think you have to persist your form data before the user land on Error.aspx. At that point a redirection has happened and all request-data would be lost. Then when the user navigates to the faulty view, you restore the form from the persisted values.

Error.aspx is a general error page, and your last resort. This page should not even try to do any task beyond general error handling.

Thomas Eyde