views:

433

answers:

3

I have an "Authorize" attribute on the Action that binds the form data.

If the user submits the form but is not authorized, the login prompt appears. Once logged in, the user is properly redirected, but the model is null.

How to handle this?

+1  A: 

This is always a problem, and is going to require you to jump through many hoops to keep this state. You can always double store the model in Session and ViewState, that way if the user comes from a place that has a null model you can look for it in the Session.

Nick Berardi
There is no ViewState in MVC, or am I mistaken?
Abyss Knight
Abyss, there is no ViewState in MVC. I love how ViewState is now a developer crutch.
Nick Berardi
+1  A: 

One thing I've thought about but never tried is displaying the login prompt as a modal dialog on the same page, rather than redirecting to a separate login page and then redirecting back. Login GUI logic is usually simple enough that you don't need a separate view for it.

For example, you could expose the login as a simple WCF service with Json message encoding, and then talk to it from your modal dialog using jQuery.

davogones
+2  A: 

A basic solution is to create a new ActionFilter attribute behaving similar to Authorize, with the difference it would store the model in Session before redirecting, the users logins then, redirects back to the data form. Then fill the data form with possibly stored values when an authorized user gets the data form, the user can submit the filled form again. You can change this as you wish, even store the data at client side which must be possible, but the main idea is to use a custom authorization ActionFilter which stores the model before redirecting, instead of Authorize.

Parsa