views:

216

answers:

2

Following the Post-Redirect-Get pattern as described in various spots but maybe in most detail here by Stephen Walter, I want to use RedirectToAction but it does not accept a parameter for sending an object to it. I can only send route values either as an object or as a RouteValueDictionary. So currently I send object ID and type and pull the object out of the datastore again in the action to which I redirected (like Results).

// redirect to confirm view
return RedirectToAction("ChangeSuccess", "Redirect",
    new { slug = tabgroup.Slug, contentType = tabgroup.ContentType });

But I would like to send an object there because I already have it in my updating controller action so I don't need to pull it out again.

Is that possible somehow?

+2  A: 

Have you read this

... One of the issue with this pattern is when a validation fails or any exception occurs you have to copy the ModelState into TempData. If you are doing it manually, please stop it, you can do this automatically with Action Filters...

Its number 13. Use PRG Pattern for Data Modification

Rippo
+1  A: 

See here.

But I would recommend to pass just ID. If you later decide to use lazy-loading, keeping entity in session will fail (because session is gone after redirect). I experienced this myself and had to rewrite many actions.

queen3
After thinking about it some time, I decided to pass the parameters as I did so far. The only difference is that now I use strongly typed RedirectToAction from MVCContrib which makes things more error prone and clear to understand.
mare