© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
30 replies
Shinigami

✅ ValidationContext in ASP.NET

What does ObjectInstance and ObjectType mean? afaik

1) ValidationContext is basically on which class the validation is performed.
2) ObjectInstance is where we have all the values for a model class
3) I'm not sure what object type is.

What does this code do here?

PropertyInfo? otherproperty = validationContext.ObjectType.GetProperty(PropertyName);

                    DateTime from_date = Convert.ToDateTime(otherproperty.GetValue(validationContext.ObjectInstance));
PropertyInfo? otherproperty = validationContext.ObjectType.GetProperty(PropertyName);

                    DateTime from_date = Convert.ToDateTime(otherproperty.GetValue(validationContext.ObjectInstance));

I'm trying to fetch a different property value from in the same model class

Model class

//Multiple Properties using Reflection
public string? FromDate { get; set; }

[DateRangeValidator("FromDate", ErrorMessage = "From Date should be less than To Date.")]
public string? ToDate { get; set; }
//Multiple Properties using Reflection
public string? FromDate { get; set; }

[DateRangeValidator("FromDate", ErrorMessage = "From Date should be less than To Date.")]
public string? ToDate { get; set; }
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Asp.net (.net461, global.asax)
C#CC# / help
15mo ago
databinding in asp.net
C#CC# / help
2y ago
Logging in ASP.NET
C#CC# / help
2y ago
❔ ✅ node in asp.net
C#CC# / help
4y ago