Hi Dario,

it's actually not that easy; Maybe I should describe the scenario a
bit more detailed. This is my Class:


public Contact {
    public int Id;

    [Valid]
    public IList<CommunicationItem> Com;
}

public class CommunicationItem {
    public int Id;
    public MyCustomClass CommunicationType;
    public string CommunicationString;
}

public MyCustomClass {
    public int Id;
    public String Type; // For example "eMail"
    public string Regex; // <= Rules are stored in here!
}

Then I'd like to validate the CommunicationItem - Object. Using
CommunicationItem.MyCustomClass.Regex as the Key. If I use my custom
EntityValidator, it's validating, but MVC does not know of course what
Property failed the validation...

By Using [Pattern(...)] its not possible to access any Property of the
class... And if I create a ValidationClass which iterates through the
IList, it stops after the first element which is invalid because I
have to return "false"...

Any Idea how to solve this?

Thanks so much!

On 27 Aug., 13:49, Dario Quintana <[email protected]>
wrote:
> Hey,
>
> You don't need an Entity-Validator (which is your CustomFooValidator). You
> can just use a Pattern validator in the property in the Foo type.
>
> public class Foo
> {
>       [Pattern(....)] //Pattern is for regex
>       public string SomeProperty {get;set;}
>
> }
>
> And then you still can have this:
>
> [Valid]
> public virtual IList<Foo> newNameofthisCollection.
>
> And remember, the custom validator comes in two flavors: Entity and Member
> (Property or Field) Validator.
>
> Another solution, remember that you can use Constraint Validator Context,
> that is, you can disable the default error in a Entity-Validator and add new
> custom messages in the 
> validator.https://nhcontrib.svn.sourceforge.net/svnroot/nhcontrib/trunk/src/NHi...
> And with Constraint Validator Context you can point an Error Message to a
> member directly, even using Entity-Validator.
>
> Cheers
>
>
>
>
>
> On Thu, Aug 27, 2009 at 3:23 AM, stromflut <[email protected]> wrote:
>
> > Hi there!
>
> > I have a collection property of a custom class "foo" (namely an
> > IList<foo>) in which class I have a property "value" and another
> > property "Regex" which holds the allowed format of "value". To
> > validate this property, I added the Attribute [Valid] on the topLevel
> > to the collection as following:
> > [Valid]
> > public virtual IList<foo> newNameofthisCollection
>
> > Then I have the CustomFooValidator class which is checking the "value"
> > property against the Regex property and returns false if the property
> > is invalid. But to make this working, i had to define the Validator to
> > be a "ClassValidator" adding "AttributeUsage(AttributeTargets.Class)"
> > to the ValidationClass Definition.
>
> > If it comes to the validation, MVC adds an InvalidValue Object to the
> > ModelState Property of the Object. The Problem is now, MVC does not
> > know to what property of "foo", it should map the InvalidValue because
> > the Object in the Collection has been validated on ClassLevel.
>
> > Does anyone know a way, how to define in the ValidationClass on what
> > property it should map the ValidationError? Or is there an other way
> > to validate the collection?
>
> > Thanks a lot, just even for reading and thinking about my problem!
>
> > //stromflut
>
> --
> Dario Quintanahttp://darioquintana.com.ar- Zitierten Text ausblenden -
>
> - Zitierten Text anzeigen -
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to