2

I am trying to redirect to a post action result from another action result function. In this case, I would like to redirect to the Index Post, from the Summary function. Is that possible?

The index page is my search page and the Post action would return results. Should a user enter an id in the address bar, the search can be performed and the results be displayed.

public ActionResult Summary(string id)
{
    //simple code
    if(true)
    {
        return RedirectToAction("Index", "Home", HttpVerbs.Post);
    }
    return View();
}
MrM
  • 21,709
  • 30
  • 113
  • 139
  • Could you provide information on why you want to do this? – Moulde Jun 13 '11 at 14:03
  • I think this answer will provide some useful context http://stackoverflow.com/questions/46582/response-redirect-with-post-instead-of-get/47735#47735 – David Ruttka Jun 13 '11 at 14:04
  • The index page is my search page and the Post action would return results. Should a user enter an id in the address bar, the search can be performed and the results be displayed – MrM Jun 13 '11 at 14:06

2 Answers2

1

See this previous answer for some context, but I would agree with the second option listed there. In your case, it might not be a third-party server, but rather your Index action that only accepts POST.

Create the form to post to your server. When the form is submitted, show the user a page that has a form in it with all of the data you want to pass on, all in hidden inputs. Just show a message like "Redirecting...". Then, add a javascript event to the page that submits the form to the third-party server.

In other words, Summary would return a View which, through JavaScript, posted to Index.

Community
  • 1
  • 1
David Ruttka
  • 14,269
  • 2
  • 44
  • 39
0

Why can't you just return a PartialView of the results back to the Index page?

mymex1
  • 148
  • 3