I have a curious problem with ASP.NET MVC3 client-side validation. I have the following class:
public class Instrument : BaseObject
{
public int Id { get
I just used a snippet of jquery to solve this problem.
$("input[data-val-length-max]").each(function (index, element) {
var length = parseInt($(this).attr("data-val-length-max"));
$(this).prop("maxlength", length);
});
The selector finds all of the elements that have a data-val-length-max attribute set. This is the attribute that the StringLength validation attribute will set.
The each loop loops through these matches and will parse out the value for this attribute and assign it to the mxlength property that should have been set.
Just add this to you document ready function and you are good to go.