MVC2 - DefaultModelBinder and DataAnnotations feedback 2 the team

Last post 08-06-2009 12:08 PM by bradwils. 3 replies.

Sort Posts:

  • MVC2 - DefaultModelBinder and DataAnnotations feedback 2 the team

    08-06-2009, 3:43 AM
    • Member
      160 point Member
    • nagir
    • Member since 01-10-2006, 12:01 AM
    • Australia
    • Posts 178

    Hi,

    It seems that MVC2 tightly integrates with DataAnnotations.

    And it seems there is no way to plug custom validator to DefaultModelBinder.

    So we have to create our own DataBinder to provide custom validation facility.


    Please provide a plugable API so we could not rely on the DataAnnotations only.

    Everybody knows it is not always possible to use Attributes and external validation is often used.
    Especially when a Model is reused accross different projects and validation rules are quite different.

    The questions about it just start to arise, but later it will be a bigger problem.

    Cheers,
    Dmitriy.

  • Re: MVC2 - DefaultModelBinder and DataAnnotations feedback 2 the team

    08-06-2009, 4:16 AM
    Answer
    • Contributor
      4,637 point Contributor
    • levib
    • Member since 07-23-2007, 7:50 PM
    • Redmond, WA
    • Posts 794
    • AspNetTeam

    The DefaultModelBinder type has always contained extensibility points to plug in your own validation logic, even in v1.  Take a look at the virtual methods on that type, specifically the OnPropertyValidating / OnPropertyValidated methods.  One is called before the property setter is called, the other after.  In fact, these existing extensibility hooks were used by the first DataAnnotationsModelBinder sample to provide DataAnnotations support for MVC v1 (which did not natively support DataAnnotations); that sample was later merged into the DefaultModelBinder.  This experiment validates that the existing hooks - while not perfect - were sufficient for including custom validation logic.

    If you have a particular validation scenario that is not satisfied with the existing hooks, please let us know the details so that we can investigate it further.  Thanks!

  • Re: MVC2 - DefaultModelBinder and DataAnnotations feedback 2 the team

    08-06-2009, 8:56 AM
    • Member
      160 point Member
    • nagir
    • Member since 01-10-2006, 12:01 AM
    • Australia
    • Posts 178

    Ohh.

    Yes. I thought the DefaultBinder's validation in MVC2 is kind of hard-coded.

    Had to check everything first.

    Sorry for the confusion.

  • Re: MVC2 - DefaultModelBinder and DataAnnotations feedback 2 the team

    08-06-2009, 12:08 PM
    Answer
    • Contributor
      2,220 point Contributor
    • bradwils
    • Member since 05-19-2008, 1:08 PM
    • Redmond, WA
    • Posts 312
    • AspNetTeam

    This "tight integration" is simply because it's Preview 1. We wanted to get you something functional to play with. :)

    We are aware of the desire for pluggability of validation and model metadata.

    Senior developer on the ASP.NET MVC team
Page 1 of 1 (4 items)