(vers 20.2.0.40)
I have used grid in my application and I use a edit dialog to edit rows.
The dialog show another grid that allow edit the detail. In the detail grid, both columns (Merma and Bonificacion) are mutually exclusive. If you set a value in one column, the other column should be null.
I create a custom validation, but unfortunatelly the message is not shown as I expected.
The model:
public class HumedadGranoItemModel
{
public HumedadGranoItemModel()
{
}
public HumedadGranoItemModel(int id, decimal porcentaje, decimal? merma =null, decimal? bonificacion= null)
{
Id = id;
Porcentaje = porcentaje;
Merma = merma;
Bonificacion = bonificacion;
}
public int Id { get; set; }
public HumedadGranoModel HumedadGrano { get; set; } = null!;
public decimal Porcentaje { get; set; }
[CustomValidationMermas]
public decimal? Merma { get; set; }
[CustomValidationMermas]
public decimal? Bonificacion { get; set; }
}
And the custom validation :
[AttributeUsage(AttributeTargets.Property)]
public class CustomValidationMermas : ValidationAttribute
{
protected override ValidationResult IsValid(object value, ValidationContext validationContext)
{
if (value != null)
{
var item = (HumedadGranoItemModel)validationContext.ObjectInstance;
if (item.Bonificacion > 0 && item.Merma > 0)
{
return new ValidationResult("La merma y a bonificación son excluyentes");
}
}
return ValidationResult.Success;
}
}
I've attached a sample project.
Please, let me know what is wrong.
Attachment:
General_162c2dbb.rar