如何使用POST重定向ASP.NET MVC? [英] How to redirect ASP.NET MVC with a POST?

查看:71
本文介绍了如何使用POST重定向ASP.NET MVC?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为一个网站设置一个付款页面,该页面首先完成了一个简单的购物车,然后当用户单击提交"时,我需要将交易数据发布到外部信用卡处理网站,然后重定向该网站的用户.一旦他们在此处输入了信用卡详细信息,该网站就会以批准或拒绝的方式重定向回我.

I am setting up a payments page for a site, which first completes a kid of simple shopping cart, then when the user clicks "Submit", I need to POST the transaction data to an external credit card processing site, and redirect the user to that site. Once they've entered their credit card details there, the site redirects back to me, either with approval or rejection.

问题是,我在MVC界面中看不到任何允许我通过POST操作重定向的内容. Redirect()方法使用GET(在第三方网站上仍然无法使用).我尝试使用 WebClient.UploadValues()进行程序化发布,然后从该字符串中获取了一个字符串,该字符串可以通过返回 Content()呈现给用户-但随后表单中的链接(应该是相对于CC处理站点)是相对于我的站点,这对我来说是无用的.

Trouble is, I can't see anything in the MVC interface that allows me to redirect with a POST action. The Redirect() method uses a GET (which doesn't work anyway on the 3rd party site). I tried doing a programmatic post using WebClient.UploadValues(), and I get back from that a string which I can present to the user by returning Content() - but then the links inside that form, which are supposed to be relative to the CC processing site, are instead interpreted as relative to my site, which is no bleedin' use to me.

我该怎么做?

推荐答案

您无法使用帖子进行重定向.

You cannot redirect using a post.

您可以执行以下操作:

  • 接收帖子并做一些事情
  • 向用户返回一个视图,该视图包含一个表单,该表单填充有包含已处理数据的隐藏字段
  • 已使用javascript自动提交了表单(已在CC提供商处设置了后操作)
  • 用户转到抄送提供者
  • 用户返回到您的网站

编辑-使用jQuery,表单ID为ccform的表单发布,其操作设置为cc提供程序的URL和隐藏字段:

EDIT - Using jQuery, form post with a form ID ccform, with the action set to the URL of your cc provider and the hidden fields :

$.ready(function() { $('#ccform').submit(); });

这篇关于如何使用POST重定向ASP.NET MVC?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆