Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/google-chrome/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# MVC2验证模型。属性也没有验证属性_C#_Asp.net Mvc - Fatal编程技术网

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