我在.NET MVC项目中使用Braintree.js来加密信用卡详细信息。积极的案例运作良好,交易成功。
问题是,我在Controller上有一些验证,当我再次显示视图时,如果出现错误,信用卡字段现在包含加密值。我尝试将模型属性设置为空字符串以清除它们,但加密值仍然存在。
有人为此提供了优雅的解决方案吗?谢谢!
我的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>
答案 0 :(得分:2)
我设法通过将HTML.TextBoxFor替换为常规输入文本框来解决此问题,如下所示:
<input type="text" autocomplete="off" data-encrypted-name="CreditInfo.CardholderName"/>
如果您正在使用MVC,请注意您的data-encrypted-name值必须与模型的属性匹配,以便在POST时正确提交。在再次显示View之后,这些字段仍然被清除,但这对我来说已经足够了。