Everything you need to achieve this is already included with the ASP.NET MVC 3.0 Beta 1 template.
Model:
public class MyViewModel
{
[Required]
public string Value { get; set; }
}
Controller:
public class HomeController : Controller
{
public ActionResult Index()
{
return View(new MyViewModel());
}
[HttpPost]
public ActionResult Index(MyViewModel model)
{
return View(model);
}
}
View:
<script type="text/javascript" src="<%: Url.Content("~/scripts/jquery-1.4.1.js") %>"></script>
<script type="text/javascript" src="<%: Url.Content("~/scripts/jquery.validate.js") %>"></script>
<script type="text/javascript" src="<%: Url.Content("~/scripts/jquery.validate.unobtrusive.js") %>"></script>
<% Html.EnableClientValidation(); %>
<% using (Html.BeginForm()) { %>
<%: Html.TextBoxFor(x => x.Value) %>
<%: Html.ValidationMessageFor(x => x.Value) %>
<input type="submit" value="OK" />
<% } %>
If you want to do the same thing with ASP.NET MVC 2.0 you will need to download the source code of ASP.NET MVC Futures and extract MicrosoftMvcJQueryValidation.js
from the package to include in your site.