Here's a snippet with displaying a person object. I'm using the layout that Bootstrap uses too ( with the control-div around the label and input )
}Edit person @Model.Name
@using (Html.BeginForm(this.Html)) {
And here's the only thing required to make unobtrusive validations work with this markup:
$.validator.setDefaults({ highlight: function (element, errorClass, validClass) { $(element).closest(".control-group") .addClass("error"); }, unhighlight: function(element, errorClass, validClass) { $(element).closest(".control-group") .removeClass("error") .addClass("success"); } });The result
Edit - it was already on StackOverflow for quite some time: http://stackoverflow.com/questions/10217175/mvc-twitter-bootstrap-unobtrusive-error-handling
Thaks for that! Simplest solution i have found
ReplyDelete