Search code examples
asp.net-mvcasp.net-mvc-3editorfor

mvc3 maxLength input


this may be kind of general but i want to limit the number of character inpit in an editorfor field.

@html.EditorFor(m=>m.id,new {@maxlength="10"})

This does not seem to work.


Solution

  • Try changing it to

    @Html.TextBoxFor(m=> m.id,  new { maxlength="10" });
    

    EditorFor uses the templates, which you can override yourself. I don't think they take into account the attributes you pass in like this. The TextBoxFox<> generates it in code, and should work fine.