Click here to Skip to main content
15,898,036 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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

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


JavaScript
<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>
Posted
Updated 5-Jul-17 5:13am

1 solution

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[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900