JDA Documentation

Here is where you can find the preliminary documentation for jda.

Decorating your models

public class Contact {
   //Requires that the Username is supplied
   [Required]
   public string Username {get;set;}

   // Requires that the Email Address is supplied and is properly formated
   [Required]
   [Email]
   public string EmailAddress{get;set;}

   // Requires that the Website Property contains a properly formated url string
   // Url is not required.
   [Url]
   public string WebSite{get;set;}
}

Html Helpers

First things first the Data Annotations must be registered by the DataAnnotationsModelValidatorProvider
this can be accomplished in the Global ASAX file
protected void Application_Start()
{
    AreaRegistration.RegisterAllAreas();
    RegisterRoutes(RouteTable.Routes);

    //This is where the magic happens
    jQueryDataAnnotationsProvider.RegisterAdapters();
}


Next up let's wire the jQuery Validation code in an ASPX page.
At the bottom of an aspx page let's place a javascript block and use our Html Helpers
<script type="text/javascript">
    -- Basic jQuery Validation stuff. It just tells jv to validate the form named createForm.
    $("#createForm").validate();
        
    -- Our code that wires up the UserName Textbox for use with jQuery Validation. you can see that even though we are
    -- using mutiple annotations we only need to call the ValidationFor method once for each property.
    <%= Html.jQueryValidationFor(model => model.UserName) %>
    <%= Html.jQueryValidationFor(model => model.EmailAddress) %>
    <%= Html.jQueryValidationFor(model => model.WebSite) %>
</script>

Last edited Jan 12, 2010 at 2:52 PM by ebertsch, version 4

Comments

No comments yet.