如何从MVC将数据发布到Action URL(How to post data to Action URL from MVC)

系统教程 行业动态 更新时间:2024-06-14 16:57:39
如何从MVC将数据发布到Action URL(How to post data to Action URL from MVC)

我是MVC的新手。 实际上,我在ASP.Net中有一个场景,我submitting data (包含Amount,RedirectURL等)提交到URL (支付网关),如下所示:

<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>

它将redirect to that payment gateway page ,成功交易后,我将被redirected back to my application页面,其中包含一些extra status codes 。

我正在通过HttpContext.Current.Request["TransactionType"];处理这些返回状态值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中的一些数据提交表单?

I'm new to MVC. Actually, I've a scenario in ASP.Net where I'm submitting data(which contains Amount,RedirectURL etc) to a URL(Payment Gateway) like this :

<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>

and it will redirect to that payment gateway page and after successful transaction, I will be redirected back to my application page with some extra status codes.

I'm handling those return status values by HttpContext.Current.Request["TransactionType"];

Now, I need to do that in MVC, but my only confusion is how to submit form.

I've tried in MVC by using :

@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> }

But, I'm getting redirected to this URL :

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

Can anyone pls help me how I can submit a form using some data in MVC?

最满意答案

为标签或使用创建html

你的控制器就像

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

和观点

@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,因此将Action和Controller设置为null。

Either create html for tag or use

Your controller be like

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

And 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> }

Since you are trying to redirect to external url, set Action and Controller to null.

更多推荐

本文发布于:2023-04-13 12:05:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/9c398d559e2ab9bb0003619a328680a9.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据   Action   MVC   data   post

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!