我有一个模型:
public class OverdraftForm
{
public string CustomerId { get; set; }
public PaymentType PaymentType { get; set; }
public OverdraftType Type { get; set; }
public decimal PermanentAmount { get; set; }
public int ExpirationPeriod { get; set; }
public decimal OnetimeAmount { get; set; }
public DateTime ExpirationDate { get; set; }
public CreditType CreditType { get; set; }
public string Comment { get; set; }
}
我的 Action 是
public ActionResult CreateOverdraft(OverdraftForm form)
{
if (form.Type == OverdraftType.Permanent)
return CreatePermanentOverdraft(form);
return CreateOnetimeOverdraft(form);
}
重点是当我调试它时,即使在操作的第一行 ModelState.IsValid 是 false,它说 OnetimeAmount 应该有一个值。我正在使用 MVC2,我猜它的某些更改会导致此问题。
最佳答案
这是 MVC2 的一个变化 - on automatic databinding, it's going to read all your properties (even the read-only ones) to try to validate them .
关于c# - MVC2 验证模型也没有属性的验证属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3494116/