我已經有了一個模型:MVC2驗證模型還沒有驗證屬性的屬性
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; }
}
而且我的行爲是
public ActionResult CreateOverdraft(OverdraftForm form)
{
if (form.Type == OverdraftType.Permanent)
return CreatePermanentOverdraft(form);
return CreateOnetimeOverdraft(form);
}
的一點是,當我調試它,甚至在第一行動作ModelState.IsValid爲false,它表示OnetimeAmount應該有一個值。我使用MVC2,我想對它的一些更改會導致此問題。
對不起,一個愚蠢的問題。但我應該怎麼做? [必需(false)]不會(也不應該)工作 – HiveHicks 2010-08-16 14:47:35
試圖使其可以爲空: 公共小數? OnetimeAmount {get;組; } – akonsu 2010-08-16 15:15:45
謝謝,它的工作原理。 – HiveHicks 2010-08-16 15:21:57