Thursday, July 5, 2012

How to set maxlength for a Textbox in MVC3?

In model add following attribute:
        [StringLength(30, ErrorMessage = "Name cannot be longer than 30 characters.")]
        public string Name { get; set; }



Try a couple of others way, doesn’t work:
@Html.EditorFor(model => model.Name, new { @maxlength = "2" })
$(“#name”).attr(“maxlength”,20);


No comments:

Post a Comment