Vibrant discussion about CSLA .NET and using the framework to build great business applications.

Forum has moved

New location: CSLA .NET forum

CSLA .NET Resources:
  • CSLA .NET forum
  • CSLA .NET home page
  • Custom validation attribute to be used in CSLA objects

    rated by 0 users
    Not Answered This post has 0 verified answers | 3 Replies | 0 Followers

    Top 500 Contributor
    30 Posts
    correodemarques posted on Fri, Jan 11 2013 3:07 PM

    I know how to create custom validation attributes and I know how to make ASP.MVC client validation work with those attributes if I implement IClientValidatable interface, but then I would need to reference System.Web.MVC in the library containing my CSLA objects.

    Is it possible to create a custom validation attribute that will be recognized by MVC without having to implement IClientValidatable?

    Something that works as System.ComponentModel.DataAnnotations.RequiredAttribute and that can be applied to CSLA properties without referencing System.Web.MVC.

    All Replies

    Top 10 Contributor
    2,279 Posts

    Any custom validation attribute that inherits from System.ComponentModel.DataAnnotations.ValidationAttribute will be used by the CSLA rule engine - just as the RequiredAttribute is.

    See this excercise on MSDN on how to create custom validation rules and plugin to ASP.NET MVC 3:

    Jonny Bekkum, Norway CslaContrib Coordinator

    Top 500 Contributor
    30 Posts

    Hi Jonny,

    Thanks for your answer.

    Yes, I already know how to create an attribute that inherit from ValidationAttribute and is recognized by CSLA.

    My question is about how to make that attribute in a way that is recognized by MVC to generate the HTML needed for the unobtrusive validation to work, without having to reference System.Web.MVC in my class library.

    If I follow the tutorial I would have to implement IClientValidatable and then if I try to apply my attribute to a property, I will need to reference System.Web.MVC in my class library. At least that is what I understood.

    Top 10 Contributor
    9,475 Posts
    This sounds like a question you might need to ask in an ASP.NET forum on MSDN or something. I've never explored this part of the DataAnnotations infrastructure.


    Page 1 of 1 (4 items) | RSS

    Copyright (c) 2006-2014 Marimer LLC. All rights reserved.
    Email admin@lhotka.net for support.
    Powered by Community Server (Non-Commercial Edition), by Telligent Systems