tags:

views:

85

answers:

2

I've got a model:

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; }
}

And my action is

public ActionResult CreateOverdraft(OverdraftForm form)
{
    if (form.Type == OverdraftType.Permanent)
        return CreatePermanentOverdraft(form);
    return CreateOnetimeOverdraft(form);
}

The point is when I debug it, even on the first line of action ModelState.IsValid is false, and it says that OnetimeAmount should have a value. I'm using MVC2, I guess some changes to it cause this problem.

+2  A: 

set the Required attribute on the field to false. by default it is true.

akonsu
Sorry for a stupid question. But how should I do that? [Required(false)] does not (and should not) work
HiveHicks
try to make it nullable:public decimal? OnetimeAmount { get; set; }
akonsu
Thanks, it works.
HiveHicks