Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

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

You could not pass an object to a GET URL.

Since RedirectToAction method issues a new GET Request to the server.

However you can pass a query string parameter to GET URL. So please try passing id as suggested by queen.

To persist your object between subsequent request i strongly advice you to use TempData. However it internally use a Session, but it kills immediately after the request.

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