0

我有一个模型 ProductModel 它具有: * bool IsNew 属性 * ProductDetailsModel 详细信息属性

public class ProductModel
{
    public bool IsNew { get; set; }
    public ProductDetails Details { get; set; }
}

public class ProductDetails
{
    public string Code { get; set; }
    public string Type { get; set; }
    public string Description { get; set; }
    public int Number { get; set; }
}

ProductDetails 有一些其他属性,例如。代码、类型、描述、编号

我想让 ProductDetailsModel 的 Description 和 Number 属性只有在ProductModelIsNew设置为 true 时才需要。

怎么做?

顺便说一句,我在 ProductModel 中有更多自定义类型的属性,我无法将它们的属性移动到单个 ProductModel 中。

4

1 回答 1

1

我在这里找到了答案ASP.NET MVC Conditional validation

在 Product 模型中实现验证似乎是最简单的方法。

于 2015-07-15T11:56:27.237 回答