C# MVC2验证模型。属性也没有验证属性
我有一个模型:C# MVC2验证模型。属性也没有验证属性,c#,asp.net-mvc,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 ExpirationP
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。默认情况下为true。将字段上的必需属性设置为false。默认情况下这是真的。这是MVC2-的变化。这是MVC2-的变化。很抱歉问了一个愚蠢的问题。但我该怎么做呢?[Requiredfalse]没有也不应该尝试将其设为空:public decimal?OnetimeAmount{get;set;}很抱歉问了一个愚蠢的问题。但我该怎么做呢?[Requiredfalse]没有也不应该尝试将其设为空:public decimal?一次性金额{get;set;}