1

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.

HiveHicks
  • 2,294
  • 5
  • 28
  • 42

2 Answers2

3

It is a change with MVC2 - on automatic databinding, it's going to read all your properties (even the read-only ones) to try to validate them.

Community
  • 1
  • 1
48klocs
  • 6,073
  • 3
  • 27
  • 34
2

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

akonsu
  • 28,824
  • 33
  • 119
  • 194