I suggest you ...

Include support for conditional validation

Often times it is necessary to perform a validation only under a certain condition, X is Required IF Y is checked...etc.

487 votes
Vote
Sign in
Check!
(thinking…)
Reset
or sign in with
  • facebook
  • google
    Password icon
    I agree to the terms of service
    Signed in as (Sign out)
    You have left! (?) (thinking…)
    M. Keith WarrenM. Keith Warren shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →

    19 comments

    Sign in
    Check!
    (thinking…)
    Reset
    or sign in with
    • facebook
    • google
      Password icon
      I agree to the terms of service
      Signed in as (Sign out)
      Submitting...
      • AlexBarAlexBar commented  ·   ·  Flag as inappropriate

        For conditional validation I use for a years the following library http://foolproof.codeplex.com/. It has a bunch of attributes like RequiredIf and they all support client side validation. It would be great if we can get the same BUILD IN functionality.

      • Nobody RealNobody Real commented  ·   ·  Flag as inappropriate

        Please, stop marking items that are clearly NOT completed as "completed" simply because someone has somewhere written some code to implement similar functionality. We're asking for this to be BUILT IN to the framework, not for it to be possible to roll your own, because everyone does it differently. If it's built in, then it's standardized.

      • Felipe Fujiy PessotoFelipe Fujiy Pessoto commented  ·   ·  Flag as inappropriate

        Client Side is the most important. Server Side is easily achieved with IValidatableObject. Definitely not complete. I'm very surprised this was marked as complete

      • Wayne BrantleyWayne Brantley commented  ·   ·  Flag as inappropriate

        Not really done. How can you do something as simple as:

        validate a date field such that the max date allowed is 'today'. Cannot do it - because everything is statically defined in the current validation implementation.

      • Travis IlligTravis Illig commented  ·   ·  Flag as inappropriate

        Agreed w/Aaron - no client side + no small amount of custom code to get it to work = not really the robust solution I was hoping for. If that's the answer, color me disappointed.

      • Aaron ShumakerAaron Shumaker commented  ·   ·  Flag as inappropriate

        @Daniel 1) MVC doesn't support this directly and 2) as indicated in the article that example doesn't support client side validation so we must all implement that ourselves.. There are some common scenarios that we are independently implementing using custom validation and it is quite tedious. It certainly isn't supported on the same level as other data annotations :(

      • PeterPeter commented  ·   ·  Flag as inappropriate

        Also decouple unbinding from validation, make it two separate calls. Sometimes I just want unbind without validation, or just want to validate certain fields or groups of fields.

      • Wayne BrantleyWayne Brantley commented  ·   ·  Flag as inappropriate

        Sure hope they get around to a better validation story before too long. What currently exists is great for simple demos, but really needs help.

      • jonjon commented  ·   ·  Flag as inappropriate

        what about multiple custom validator on a property as mvc is providing multiple custom validator on class right now ?

      • grahamonealegrahamoneale commented  ·   ·  Flag as inappropriate

        How about conditional validation (both client & server) depending on what page you're on? For instance, if I have a User Add page I might validate Password, but if it's the User Edit page, password validation is not required. I would have thought this is a fundamental requirement, but it seems it's not supported.

        But I agree with the guys, I think this needs to be achieved using a Fluent Validation style approach with RuleSets.

      • LobstrosityLobstrosity commented  ·   ·  Flag as inappropriate

        What would this provide that IValidatableObject doesn't? Or is it just a matter of usage?

      • Wayne BrantleyWayne Brantley commented  ·   ·  Flag as inappropriate

        Be very nice if something like FluentValidation was baked in. For example, how can you validate a date field such that the max date allowed is 'today'. Cannot do it - because everything is statically defined in the current validation implementation.

      • M. Keith WarrenM. Keith Warren commented  ·   ·  Flag as inappropriate

        I get that it is simple to implement and I have done one for my personal projects but I think it makes a good candidate for being baked into the bits.

      • ZoteZote commented  ·   ·  Flag as inappropriate

        It's very simple to implement this. You can get some sample at Brad Wilson's blog. Or, if you need, I can help you.

      Feedback and Knowledge Base