更新时间:2023-02-13 09:33:24
(#stripeToken)。val(token.id);
(#stripeEmail) .VAL(token.email);
( #myForm会)提交();
}
});
// var handler = StripeCheckout.configure({
// key:pk_test_77oo7uz7BCoBk2vPq2OvhHLp,
// image:https://stripe.com/img/documentation/checkout/marketplace .png,
//名称:Abacus,
//说明:专业订阅套餐,
//按钮:提交,
// panelLabel: 订阅,
// allowRememberMe:false
//});
@ * var el = document.getElementById(SubsID);
I want pass model data from button to controller.Passed the button id but null value is return.
What I have tried:
Plan details in view page
<div class="plans"> @foreach (var item in Model) { <div class="plan"> <h3 class="plan-title">@Html.DisplayFor(modelItem => item.Id1)</h3> <h3 class="plan-title">@Html.DisplayFor(modelItem => item.Name1)</h3> <p class="plan-price">@Html.DisplayFor(modelItem => item.Currency1)@Html.DisplayFor(modelItem => item.Amount1) <span class="plan-unit">@Html.DisplayFor(modelItem => item.IntervalCount1)-@Html.DisplayFor(modelItem => item.Interval1)</span></p> <ul class="plan-features"> <li class="plan-feature">@Html.DisplayFor(modelItem => item.Trial1)-days <span class="plan-feature-name">Trial</span></li> </ul> @*<h3 class="plan-title">@item.Name</h3> <p class="plan-price">@item.Currency@(int.Parse(item.Amount) / 100)<span class="plan-unit">per month</span></p> <ul class="plan-features"> <li class="plan-feature">@item.TrialPeriodDays-Days <span class="plan-feature-name">Trial</span></li> </ul>*@ <input type="hidden" name="EmployeeId" id="planid" value="@item.Id1" /> <button class="plan-button demo" id="btnSubmit" name="btnSubmit" onclick="test(this)" >Choose Plan</button> </div> } </div>
Check out form in view page
<form id="myForm" action="@Url.Action("SuperOffer", "Home")" method="POST"> <input type="hidden" id="stripeToken" name="stripeToken" /> <input type="hidden" id="stripeEmail" name="stripeEmail" /> <input type="hidden" id="btnSubmit" name="btnSubmit" /> <script src="https://checkout.stripe.com/checkout.js"></script> <script> var email = "NotNotSeven@hotmail.com"; var handler = StripeCheckout.configure({ key: 'pk_test_77oo7uz7BCoBk2vPq2OvhHLp', image: 'https://stripe.com/img/documentation/checkout/marketplace.png', token: function (token) { $("#stripeToken").val(token.id); $("#stripeEmail").val(token.email); $("#myForm").submit(); } }); //var handler = StripeCheckout.configure({ // key: "pk_test_77oo7uz7BCoBk2vPq2OvhHLp", // image: "https://stripe.com/img/documentation/checkout/marketplace.png", // name: "Abacus", // description: "Pro Subscription Package", // button: "Submit", // panelLabel: "Subscribe", // allowRememberMe: false //}); @*var el = document.getElementById("SubsID"); $('el').click(function (e) { $.ajax({ type: "POST", url: '@Url.Action("Superoffer", "Home")', datatype: "json", traditional: true, success: function (data) { } }) e.preventDefault(); });*@ //var CustomerEmail = Session["Email"]; var el = document.getElementsByClassName("demo"); for (var i = 0; i < el.length; i++) { el[i].addEventListener('click', function (e) { handler.open({ email: email }); e.preventDefault(); }); } //document.getElementsByClassName("plan-button").addEventListener('click', function (e) { // handler.open(); // e.preventDefault(); //}); </script> <script> function test(btn) { $('#hdntemp').remove(); $('#form').append('<input type="hidden" id="hdntemp" name="btnSubmitValue" value="' + btn.value + '" />'); } </script> </form>
controller
here email and token coming right like this i need particular plan id which we select in view page
public ActionResult Superoffer(string stripeToken, string stripeEmail, FormCollection form)
("#stripeToken").val(token.id);
("#stripeEmail").val(token.email);
("#myForm").submit(); } }); //var handler = StripeCheckout.configure({ // key: "pk_test_77oo7uz7BCoBk2vPq2OvhHLp", // image: "https://stripe.com/img/documentation/checkout/marketplace.png", // name: "Abacus", // description: "Pro Subscription Package", // button: "Submit", // panelLabel: "Subscribe", // allowRememberMe: false //}); @*var el = document.getElementById("SubsID");