I have an EditForm, and am having some problems in that something is causing a validation error, but not something bound to a control on the form.
To clarify, I have a model for the form (some properties removed for clarity)...
public class RenewalViewModel {
public int CurrentTermId { get; set; }
public DateTime Start { get; set; }
public DateTime End { get; set; }
public ObservableCollection<CompanyOverview> AvailableCompanies { get; set; }
}
CurrentTermId is not shown on the form, but is needed to identity the term when the form is submitted. Start, End and some omitted properties are displayed on the form, can be edited by the user, ad are what is used when saving the data.
Along with those, there are a few properties, such as AvailableCompanies that hold data needed for validation, but are not used when the form is submitted. I need them on the model so the validator can see them (I'm using FluentValidation).
I suspect, but am not sure, that somehow, one of these associated properties (eg a CompanyOverview or something associated with that) has been changed, and is in an invalid state. However, I don't know how to find out what property of which object is causing the validation error in order to work out why it's happening.
In order to try and work out what was happening, I changed the form's submit handler to look like this...
private void OnSubmitRenew(EditContext ec) {
if (ec.ValidateObjectTree()) {
// Save the data
} else {
Debug.WriteLine("Invalid data: " + string.Join(". ", ec.GetValidationMessages()));
}
}
The problem is that this only shows the validation errors, not which properties caused them.
Is there a way of working out which properties caused the errors? I had a look in the EditContext, but can't see anything useful in there.
Thanks