SeanJ
✅ ValidationContext in ASP.NET
var model = (User)validationContext.ObjectInstance;
Exactly, the above now gives you access to your whole model and it's properties.
Something to consider though:
1. Do you really want to just apply the validation to one out out of the two properties?
Why? Well errors/feedback, you may want to have 1 error on the FromDate and another on the TooDate that feedbacks to the user
31 replies
✅ ValidationContext in ASP.NET
Sounds like you're beginning to understand it.
Do you have the whole method?
In theory Convert.ToDateTime(otherproperty.GetValue(validationContext.ObjectInstance)); is redundant as if you look at my above the Override for ValidationResult passes the value in directly.
31 replies
✅ ValidationContext in ASP.NET
Think of it as like the context of what's being validated. Look at my recent code for example:
It provides you access to the context of that validation that's being run (Sorry if this is a bad explanation). I can now view all the properties on my model and see their values etc. Hence why you use it to get the value of whatever property you're validating
31 replies
❔ ✅ C# .NET issue, pretty simple problem but im new lol
MessageBox.Show("Successfully Registered! + (Username.Text)", "KeyAuth", MessageBoxButtons.OK, MessageBoxIcon.Information);
The errors I see here is string interpolation as IceGPT said. Just so you fully understand. To use string interpolation you need to do this:
We include a $ sign before the string and encapsulate your variables in {} rather than round brackets
not this:
30 replies