Questions tagged [ivalidatableobject]
40 questions
206
votes
8 answers
How do I use IValidatableObject?
I understand that IValidatableObject is used to validate an object in a way that lets one compare properties against each other.
I'd still like to have attributes to validate individual properties, but I want to ignore failures on some properties in…

zrg
- 4,247
- 3
- 17
- 11
16
votes
2 answers
What is the purpose of ValidationContext when implementing IValidatableObject
I have implemented IValidatableObject several times and have never found out what the purpose of parsing ValidationContext to the Validate method is - my typical IValidatableObject implementation looks something like this:
public…

Henrik Stenbæk
- 3,982
- 5
- 31
- 33
10
votes
2 answers
IDataErrorInfo vs IValidatableObject?
Currently my business objects implement IDataErrorInfo. Since I intend to use these libraries in ASP.NET MVC 3, I figure I should implement IValidatableObject as well or maybe instead of.
Does WPF work with IValidatableObject?
How do…

Jonathan Allen
- 68,373
- 70
- 259
- 447
9
votes
1 answer
IValidatableObject passes validation but StringLength is Invalid
I have a test class with a couple tests that check to see if the entity IsValid. I moved to using IValidatableObject from having my own custom validation but I'm stuck with the correct validation technique.
This is my Test…

CD Smith
- 6,597
- 7
- 40
- 66
8
votes
1 answer
IValidatableObject Validate method firing when DataAnnotations fails
I've a ViewModel which has some DataAnnotations validations and then for more complex validations implements IValidatableObject and uses Validate method.
The behavior I was expecting was this one: first all the DataAnnotations and then, only if…

Diego
- 16,436
- 26
- 84
- 136
6
votes
0 answers
PageModel and IValidatableObject - validation is not invoked
I tried to implement IValidatableObject on my Razor Page model in ASPNET Core 2.
I was surprised that the Validate method was not invoked. Moving all [BindableProperty]s to a new type implementing IValidatableObject did work, however.
Is this the…

Ronnie Overby
- 45,287
- 73
- 267
- 346
5
votes
3 answers
ASP.NET Custom ErrorMessage for Model Enum field
I am developing a website built on EntityFrameworkCore and targeting ASP.NET Core 2.1. I want to specify an error message for an enum field in my model like so:
[Required(ErrorMessage = "Select an item from the list.")]
public MyEnum MyEnum { get;…

Matthew Peltzer
- 128
- 1
- 10
5
votes
1 answer
C# Web Api - IValidatableObject validationContext service provider is null
I am trying to use IValidatableObject validation in a web api 2 context. The Validate method is getting called, but the ValidationContext parameter passed has a method called GetService which always returns null because the service provider of the…

Samuel Poirier
- 1,240
- 2
- 15
- 30
5
votes
1 answer
Controller.ValidateModel method. How it work?
I have the following model class:
public abstract class CompanyFormViewModelBase
{
public CompanyFormViewModelBase()
{
Role = new CompanyRoleListViewModel();
ContactPerson = new PersonListViewModel();
Sector = new…

Oleg Sh
- 8,496
- 17
- 89
- 159
5
votes
3 answers
Does ASP.NET web API support IValidatableObject?
I have a view model that implements IValidatableObject and also has several validation attributes. When I attempt to call an action on my ApiController, only the attribute validation is performed. Does ASP.NET Web API not support IValidatableObject?…

Chris
- 27,596
- 25
- 124
- 225
3
votes
3 answers
How to perform validation of a model of an inherited class when its base class also has validation?
Well, my problem is that I am creating an api using aspnetcore 2.1, to avoid code duplication I have created an abstract class with the properties that share the dtos (board, boardforcreation, boardforupdate, etc). I added to the abstract class…

PalaDiNNFoX
- 33
- 1
- 4
3
votes
1 answer
IValidatableObject in separate assemblies
Hi I'm trying to implement IValidableObject interface on a ASPNET MVC 4 project. My model is in a different assembly, when the framework executes my validate method it shows no validationContext and shows me this error:
validationContext Cannot…

Eduardo Cucharro
- 525
- 1
- 4
- 14
2
votes
3 answers
IValidatableObject only in some actions
I have a model that implement IValidatlableObject, and so custom error checking through Validate method.
When I create an object all is fine, but when I try to edit that object, I wan't to do that custom validation.
How can I know from wich action…

Tekno
- 193
- 1
- 1
- 11
2
votes
2 answers
ValidationResult Returned From IValidatableObject.Validate Is Not Localized
In my ASP.NET MVC3 site, I am using the following as a View Model:
using DataResources = Namespace.For.The.Localization.Resources.IndexViewModel;
public class IndexViewModel, IValidatableObject {
private string _field1_check_value = "foo";
…

Raleigh Buckner
- 8,343
- 2
- 31
- 38
2
votes
3 answers
Two checks IValidatableObject in one entity
Is the essence of Project, the creation of which is necessary to check whether there is already an entity with the same name. When editing needs such as checking, but keep in mind that the old and the new name of the entity can be matched.
You also…

Ateist
- 137
- 2
- 11