I tried this for all the inputs in my html document(textarea,inputs,etc) that had the data-val-length-max property and it works correctly.
$(document).ready(function () {
$(":input[data-val-length-max]").each(function (index, element) {
var length = parseInt($(this).attr("data-val-length-max"));
$(this).prop("maxlength", length);
});
});