I Just starting out w/ ASP.NET MVC 3 and I am trying to render out the following HTML for the string properties on a ViewModel on the create/edit view.
Instead of the StringLength
attribute (because it's a validator attribute not a metadata provider) you can use the AdditionalMetadata
attribute. Sample usage:
public class ViewModel
{
[AdditionalMetadata("maxLength", 30)]
public string Property { get; set; }
}
Basically it puts the value 30 under the key maxLength in the ViewData.ModelMetadata.AdditionalValues
dictionary. So you can use it your EditorTemplate: