Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 845
CodeNoob Avatar asked May 28 '12 12:05

CodeNoob


1 Answers

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.

like image 176
Andrew Avatar answered Sep 29 '22 12:09

Andrew