我在我的 .NET MVC 项目中使用 Braintree.js 来加密信用卡详细信息。正面案例效果很好,交易成功。
问题是,我对控制器进行了一些验证,如果出现错误,当我再次显示视图时,信用卡字段现在包含加密值。我尝试将模型属性设置为空字符串以清除它们,但加密值仍然存在。
有人对此有一个优雅的解决方案吗?谢谢!
我的 html 代码如下所示:
<script type="text/javascript" src="https://js.braintreegateway.com/v1/braintree.js"></script>
<script type="text/javascript">
var braintree = Braintree.create("key");
braintree.onSubmitEncryptForm('braintree-payment-form');
</script>
@model SubscriptionModel
<form action="@Url.Action("Subscribe", "Home")" method="POST" id="braintree-payment-form">
<ul>
<li>
<div class="text">@Html.TextBoxFor(x => x.CreditInfo.CardholderName, new Dictionary<string, object> { { "data-encrypted-name", "CreditInfo.CardholderName" } })</div>
</li>
<li>
<div class="text">@Html.TextBoxFor(x => x.CreditInfo.CardNumber, new Dictionary<string, object> { { "data-encrypted-name", "CreditInfo.CardNumber" } })</div>
</li>
<li>
<div class="text">@Html.TextBoxFor(x => x.CreditInfo.Cvv,new Dictionary<string, object> { { "data-encrypted-name", "CreditInfo.Cvv" } })</div>
</li>
<li>
<div class="text">
@Html.TextBoxFor(x => x.CreditInfo.ExpirationMonth, new Dictionary<string, object> { { "data-encrypted-name", "CreditInfo.ExpirationMonth" } })<div>
@Html.TextBoxFor(x => x.CreditInfo.ExpirationYear, new Dictionary<string, object> { { "data-encrypted-name", "CreditInfo.ExpirationYear" } })
</div>
</li>
</ul>
<button>Submit</button>
</form>