【发布时间】:2013-10-14 05:57:37
【问题描述】:
我正在尝试为 SagePay 通知创建模型。我知道 MVC 模型绑定器会根据 POST 名称自动绑定我的所有属性。
SagePay 系统传递以下表单名称:
Status
VendorTxCode
VPSTxId
VPSSignature
StatusDetail
AVSCV2
AddressResult
PostCodeResult
CV2Result
GiftAid
3DSecureStatus
CAVV
AddressStatus
PayerStatus
CardType
Last4Digits
DeclineCode
ExpiryDate
FraudResponse
BankAuthCode
我创建了以下类。
public class NotificationModel
{
public string Status { get; set; }
public string VendorTxCode { get; set; }
public string VPSTxId { get; set; }
public string VPSSignature { get; set; }
public string StatusDetail { get; set; }
public string AVSCV2 { get; set; }
public string AddressResult { get; set; }
public string PostCodeResult { get; set; }
public string CV2Result { get; set; }
public string GiftAid { get; set; }
// When binding the model will MVC ignore the underscore?
public string _3DSecureStatus { get; set; }
public string CAVV { get; set; }
public string AddressStatus { get; set; }
public string PayerStatus { get; set; }
public string CardType { get; set; }
public string Last4Digits { get; set; }
public string DeclineCode { get; set; }
public string ExpiryDate { get; set; }
public string FraudResponse { get; set; }
public string BankAuthCode { get; set; }
}
很遗憾,c# 属性名称不能以数字开头。如何让模型绑定器自动将 3DSecureStatus 帖子名称绑定到属性?
【问题讨论】:
-
是否有理由不能将列命名为 ThreeDSecureStatus(或类似名称)?
-
你看过this question吗?
-
我无法控制名称。这些由第 3 方的 API 发布到我的控制器。
-
如果您想编写自定义模型绑定器,answer 将提供您需要的任何东西
标签: c# asp.net-mvc asp.net-mvc-4 opayo