0

I have a model ProductModel which has: * bool IsNew property * ProductDetailsModel Details property

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 has some other properties eg. Code, Type, Description, Number

I would like to make Description and Number property of ProductDetailsModel required only if IsNew of ProductModel is set to true.

How to do it?

BTW I have more properties of custom types within ProductModel and I can't move their properties into single ProductModel.

tereško
  • 58,060
  • 25
  • 98
  • 150
nickornotto
  • 1,946
  • 4
  • 36
  • 68

1 Answers1

1

I found the answer here ASP.NET MVC Conditional validation

It seems the easiest way to do it to implement validation in the Product model.

Community
  • 1
  • 1
nickornotto
  • 1,946
  • 4
  • 36
  • 68