title: How can I format values in a table using the DisplayFormat attribute?
body: <p>I'm trying to understand how I can format some values in a simple table using the <code>DisplayFormat</code> attribute. <code>@Html.DisplayFor</code> seems to only support use cases where we're trying to directly format something on the model. But here the model is an enumeration of ViewModels.</p>
  
  <p>The ViewModel:</p>
  
  <pre><code>class PersonViewModel
  {
      public string Name { get; set; }
  
      [DisplayFormat(DataFormatString = @"{0:dd MMM yyyy}")]
      public DateTime? DateOfBirth { get; set; }
  
      [DisplayFormat(DataFormatString = @"{0:dd MMM yyyy}")]
      public DateTime? DateOfRegistration { get; set; }
  }
  </code></pre>
  
  <p>And the view:</p>
  
  <pre><code>@model IEnumerable&lt;PersonViewModel&gt;
  
  &lt;table&gt;
  @foreach (var person in Model)
  {
    &lt;tr&gt;
      &lt;td&gt;@person.Name&lt;/td&gt;
      &lt;td&gt;@person.DateOfBirth&lt;/td&gt;
      &lt;td&gt;@person.DateOfRegistration&lt;/td&gt;
      &lt;td&gt;@Html.DisplayFor(model =&gt; model.???) &lt;!-- can't use this here --&gt;
    &lt;/tr&gt;
  }
  &lt;/table&gt;
  </code></pre>