Note that there are some explanatory texts on larger screens.

plurals
  1. POSet Items collection of ValidationContext on IValidatableObject?
    text
    copied!<p>I have a view model class that derives from IValidateableObject, and I am using the Validate method with ValidationContext to evaluate it from my controller. </p> <p>I would like to be able to test against more than the properties of the view model class itself in ObjectInstance. I could probably add these things to the model and then everything would be easy, but I don't feel like these things really belong in the view model class, as they are more about the current state of that object.</p> <p>I was wondering if the Items collection in ValidationContext is an appropriate place to store such things... The only problem is that I can't seem to find a resource that explains how I would go about adding things to that dictionary. </p> <p>Does that make sense? Can anyone provide an explanation for how to populate ValidationContext.Items prior to checking the ModelState of an object?</p> <p>UPDATE #1 - I found the following on an old blog entry about EF CTP5 (), but I'm not sure how to use this information:</p> <blockquote> <p>Therefore it is possible to use custom validation logic that can completely replace built-in validation or filter out some validation errors returned by built-in validation. One more little detail about DbContext.ValidateEntity(<a href="http://blogs.msdn.com/b/adonet/archive/2010/12/15/ef-feature-ctp5-validation.aspx" rel="nofollow">http://blogs.msdn.com/b/adonet/archive/2010/12/15/ef-feature-ctp5-validation.aspx</a>) method is the second parameter of this method which looks like this: </p> <p><code>IDictionary&lt;object, object&gt; items</code></p> <p>By default its value is always null. However overriding DbContext.ValidateEntity() allows to pass a non-null value to this method by calling: </p> <p><code>return base.ValidateEntity(entityEntry, myItems);</code></p> </blockquote> <p>UPDATE #2 - I tried to go down the path of using a custom model binder, but I'm hitting a wall with that too - there does not seem to be a way to simply add items to the ValidationContext and then call the base.OnModelUpdated(controllerContext, bindingContext) method.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload