且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何从MVC中的视图页面调用操作

更新时间:2023-02-19 11:09:16

一些事情

- 您忘记包含所需的API'密钥'

- 您忘记了货币和金额,我还设置了区域设置:'auto'

- 你还记得顶部的jquery吗?

- 当用户批准付款时你应该指定一个令牌部件功能



见实例: stripe.com/docs [ ^ ]



i没有得到你的表单部分,如果你使用'@',那是否意味着你想使用Razor viewengine?

如果是这样,表格就会这样开始:

 @using(Html.BeginForm(Action,Controller,FormMethod.Post))
{



您想使用常规的html表单吗? ?在这种情况下,你不应该尝试发布到控制器,因为post是一个基于页面的概念,而是你应该抓住提交按钮事件并做一个ajax帖子,因为你必须在提交它之前在客户端获得tripe结果如果你专门使用条纹,不要考虑直接发布值。



< form id =funnyform> 

< input type =buttonid =mysubmitvalue =submit />

< script type =javascript>
document.getElementById('mysubmit')。addEventListener('click',function(e){
//使用条形$调用的表单和/或return方法向控制器发送ajax帖子b $ b e.preventDefault();
});
< / script>
< / form>



示例ajax post

asp.net mvc - MVC ajax json发布到控制器操作方法 [ ^ ]


I have a button inside for each loop,if i click the button display the popup using java script.Pop up view also in java script.In popup window another button is there"Subscribe button".If i click subscribe need to go home controller action method.

What I have tried:

Here i am using

form action="@Url.Action("Superoffer")" method="POST"

for calling the action but not working

<button class="plan-button demo" >Choose Plan</button>



<form action="@Url.Action("Superoffer")" method="POST">
            <script src="https://checkout.stripe.com/checkout.js"></script>
            <script>
                var handler = StripeCheckout.configure({
                    key: "",
                    image: "https://stripe.com/img/documentation/checkout/marketplace.png",
                    name: "Abacus",
                    description: "Pro Subscription Package",
                    panelLabel: "Subscribe",
                    allowRememberMe: false
                });
                var el = document.getElementsByClassName("demo");
                for (var i = 0; i < el.length; i++) {
                    el[i].addEventListener('click', function (e) {
                        handler.open();
                        e.preventDefault();
                    });
                }
                //document.getElementsByClassName("plan-button").addEventListener('click', function (e) {
                //    handler.open();
                //    e.preventDefault();
                //});
            </script>

            <div class="spelled-out">ABACUS</div>

</form>

A couple of things
- You forgot to include your API 'key' that is required
- you forgot currency and amount and i'd also set locale: 'auto'
- did you remember jquery in the top?
- You should specify a token part function to be called when user has approved payment

See for instance: stripe.com/docs[^]

i don't get your form part, if you use '@' does that mean you wanna use Razor viewengine?
If so a form would start something like this:
@using (Html.BeginForm("Action", "Controller", FormMethod.Post))
{


Would you like to use a regular html form? in that case you shouldn't attempt to post to a controller as post is a page based concept, instead you should catch the submit button event and do an ajax post, because you have to get the tripe result on the client before submitting it doesn't add value to consider posting directly if you're using stripe specifically.

<form id="funnyform">

<input type="button" id="mysubmit" value="submit/>

<script type="javascript">
 document.getElementById('mysubmit').addEventListener('click', function (e) {
           //Do an ajax post to your controller with the values you want from your form and/ or return method invoked by stripe
            e.preventDefault();
        });
</script>
</form>


Example of ajax post
asp.net mvc - MVC ajax json post to controller action method[^]