开发者

Can I redirect to a [AcceptVerbs(HttpVerbs.Post)] ActionResult?

开发者 https://www.devze.com 2023-03-12 07:06 出处:网络
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?

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 开发者_StackOverflowsearch 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();
}


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消