Project Description
The library allows to use simple attributes on actions to enable client side (based on the jquery plugin) and server side validation.

Sample:

View:
<script src="http://ajax.microsoft.com/ajax/jquery/jquery-1.4.2.js" type="text/javascript"></script>
<script src="http://ajax.microsoft.com/ajax/jquery.validate/1.7/jquery.validate.min.js" type="text/javascript"></script>

<% using (Html.BeginForm("Register", "Account", FormMethod.Post, new { id = "form1" }))
{ %>
<%= Html.TextBox("testBox")%>
<%= Html.ValidationMessage("testBox")%>
...


Controller:

public class AccountController : Controller
{
   [ValidateForm("form1", false)] // here we set validateOnExecute = false to disable server side validation because we don't need it for this action
   [Required("testBox", JQueryErrorMessage = "Required", ServerErrorMessage = "Required")]
   [MinLength("testBox", 4)]
   public ActionResult Register()
   {
      return View();
   }

   [HttpPost]
   [ValidateForm("form1")]
   [Required("testBox", JQueryErrorMessage = "Required", ServerErrorMessage = "Required")]
   [MinLength("testBox", 4)]
   public ActionResult Register(RegisterModel model)
   {
      if (ModelState.IsValid)
      { ... }
      ...
   }

   ...
}


Supported Validators:
  • Required
  • MinLength
  • MaxLength
  • RangeLength
  • Min
  • Max
  • Range
  • Number
  • Digits
  • Date
  • Email
  • Url

Last edited Aug 28, 2010 at 8:20 PM by d_roman, version 22