How do I get my custom requiredif attribute to prevent other attributes from firing

Posted by user1757804 on Stack Overflow See other posts from Stack Overflow or by user1757804
Published on 2012-10-18T22:57:52Z Indexed on 2012/10/18 23:00 UTC
Read the original article Hit count: 202

I'm working on an MVC application.

I've decorated a property with EqualTo found here: http://dataannotationsextensions.org/EqualTo/Create As well as a custom RequiredIf attribute as suggested here: http://blogs.msdn.com/b/simonince/archive/2011/02/04/conditional-validation-in-asp-net-mvc-3.aspx

My issue is that even when the field is supposed to be required and isn't the EqualTo logic is firing. So I get error messages saying the field is required but also that the field doesn't match.

If I replace the Requiredif with a regular Required only the Required message will show.

What I'm trying to figure out is how the EqualTo logic is prevented when combined with the Required attribute but not prevented when combined with my custom RequiredIf.

Any suggestions would be most appreciated, I've been racking my brain most of the day trying to figure out the mvc internals around Required.

© Stack Overflow or respective owner

Related posts about mvc

Related posts about validation