In order to get placeholder or maxLength or other Html attributes to work with the Html.EditorFor methods, you need to create an override file in Views\Shared\EditorTemplates\string.cshtml.
@{
// make placeholder work
// http://stackoverflow.com/questions/5824124/html5-placeholders-with-net-mvc-3-razor-editorfor-extension
// from [Display(Prompt =
IDictionary<string, object> attributes = new Dictionary<string, object>();
if (!string.IsNullOrEmpty(ViewData.ModelMetadata.Watermark))
{
attributes.Add("placeholder", ViewData.ModelMetadata.Watermark);
}
// http://setiabud.blogspot.com/2010/08/stringlength-validator-into-maxlength.html
IEnumerable<ModelValidator> validators = ModelValidatorProviders.Providers.GetValidators(ViewData.ModelMetadata, ViewContext);
ModelClientValidationRule stringLengthRule = validators.SelectMany(v => v.GetClientValidationRules()).FirstOrDefault(m => m.ValidationType == "length");
if (stringLengthRule != null && stringLengthRule.ValidationParameters.ContainsKey("max"))
{
attributes.Add("maxlength", stringLengthRule.ValidationParameters["max"]);
}
// this approach would grab it from the @Html.EditorFor(model => model.FirstName, new { MaxLength = 10})
// http://stackoverflow.com/questions/1625327/editorfor-and-html-properties
// if (ViewData["maxLength"] != null)
// {
// attributes.Add("maxLength", (int)ViewData["maxLength"]);
// }
}
<span>
@Html.TextBox("", ViewData.TemplateInfo.FormattedModelValue, attributes)
</span>