Hi @J Fisher,
I only want validation to happen if submit == "Submit". But it is validating when submit == "Save", despite RequiredIf. Note: It seems Foolproof, or the equivalent, is included with VS2022, since RequiredIf was already defined without NuGet.
I think RequiredIf requires the nuget package. Your code RequiredIf was already defined. Did you customize the RequiredIfTrueAttribute yourself?
As Bruce said (to use RequiredIf with an entity model, the value you are testing for must be a column in the table.).
So I defined public string submit { get; set; }
for testing purposes.Maybe you're not using RequiredIf correctly so it's validating when submit == "Save"
Maybe you can try catching the details of DbEntityValidationException.
try
{
db.SaveChanges();
}
catch (DbEntityValidationException ex)
{
foreach (var entityValidationErrors in ex.EntityValidationErrors)
{
foreach (var validationError in entityValidationErrors.ValidationErrors)
{
Response.Write("Property: " + validationError.PropertyName + " Error: " + validationError.ErrorMessage);
}
}
}