gpt4 book ai didi

c# - 如何从 MVC 将数据发布到 Action URL

转载 作者:行者123 更新时间:2023-11-30 16:52:25 24 4
gpt4 key购买 nike

我是 MVC 新手。
实际上,我在 ASP.Net 中有一个场景,我正在向 URL(支付网关)提交数据(包含金额、RedirectURL 等),如下所示:

<form id="form1" runat="server" method="post" action="https://test2pay.ghl.com/IPGSG/Payment.aspx">
<div>
<%=eGHLPurchaseItems%>
<input type="submit" value="Pay Now" />
</div>
</form>

它会重定向到该支付网关页面,在交易成功后,我会被重定向回我的应用程序页面,其中包含一些额外的状态代码.

我通过 HttpContext.Current.Request["TransactionType"]; 处理这些返回状态值

现在,我需要在 MVC 中这样做,但我唯一的困惑是如何提交表单。

我在 MVC 中尝试使用:

@using (@Html.BeginForm("https://test2pay.ghl.com/IPGSG/Payment.aspx", null, FormMethod.Post)){
<button type="submit" class="btn btn-lg b-primary">Proceed to Payment</button>
}

但是,我被重定向到这个 URL:

http://localhost:62414/Billing/https%3a/test2pay.ghl.com/IPGSG/Payment.aspx

任何人都可以帮助我如何使用 MVC 中的一些数据提交表单吗?

最佳答案

为标签创建 html 或使用

你的 Controller 就像

ViewBag.CustId = "101";
ViewBag.Email = "cust@sss.sss";

和 View

 @Html.BeginForm(null, null, FormMethod.Post, new {@action="https://test2pay.ghl.com/IPGSG/Payment.aspx"})
{
@Html.Hidden("id", @ViewBag.CustId);
@Html.Hidden("email", @ViewBag.Email);
<button type="submit" class="btn btn-lg b-primary">Proceed to Payment</button>
}

由于您正尝试重定向到外部 url,请将 ActionController 设置为 null。

关于c# - 如何从 MVC 将数据发布到 Action URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32605407/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com