MVC2验证模型,也没有属性的验证属性

时间:2010-08-16 14:33:35

标签: c# asp.net-mvc

我有一个模特:

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,我猜它的一些变化会导致这个问题。

2 个答案:

答案 0 :(得分:3)

答案 1 :(得分:2)

将字段上的Required属性设置为false。默认情况下是真的。

相关问题