title: MVC5: Can @Html.TextBoxFor (or EditorFor) get its MaxLength from the Model's Data Annotation?
body: <p>It seems like there should be a way of specifying a Model annotation like:</p>
  
  <pre><code>[Display(Name="State")]
  [MaxLength(2)]
  public string State { get; set; }
  </code></pre>
  
  <p>so that when it is used in an EditorFor or TextBoxFor, like:</p>
  
  <pre><code>@Html.EditorFor(model =&gt; model.State)
  </code></pre>
  
  <p>or</p>
  
  <pre><code>@Html.EditorFor(model =&gt; model.State)
  </code></pre>
  
  <p>the generation of the html would set the input field's maxlength to 2.  Right now, I need to do this:</p>
  
  <pre><code>@Html.TextBoxFor(model =&gt; model.State, new { maxlength = 2 })
  </code></pre>
  
  <p>Since this violates the DRY principle, I'm wondering if there is already a built in way to have this flow from the data annotations to the input field?</p>