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.
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.
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.
I was able to get it working in IE11 using the EditorFor and using multiple attributes.
@Html.EditorFor(model => model.CourseNumber, new { htmlAttributes = new { @style = "width:100px", @maxlength="10" } })
@Html.EditorFor(model => model.CourseNumber, new { htmlAttributes = new { maxlength=10 } })
–
Pretext In MVC3, this is better:
[StringLength(10, ErrorMessage = "Name cannot be longer than 10 characters.")]
public string Name { get; set; }
Specifies the minimum and maximum length of characters that are allowed in a data field. as in this https://mcmap.net/q/236749/-maxlength-attribute-not-generating-client-side-validation-attributes
MaxLength
nor StringLength
added the attribute maxlength
, instead I only got data-val-length-max
and data-val-maxlength-max
. –
Bindery © 2022 - 2024 — McMap. All rights reserved.
@Html.TextBox("", ViewData.TemplateInfo.FormattedModelValue, new { placeholder = ViewData.ModelMetadata.Watermark })
how can I get "max" from metadata? – Antinucleon