title: MVC3 data-val-* attributes not emitted from model editor template
body: <p>I have created an editor template for one of my models in my current MVC3 project. This model is calling the correct editors for the properties of the underlying mode, but they're missing the unobtrusive data-val-* attributes for validation.</p>
  
  <p>How can I get MVC to emit the data-val attributes?</p>
  
  <p>Here's my model</p>
  
  <pre><code>[MetadataType(typeof(FieldTripRouteMetadata))]
  public partial class FieldTripRoute
  {
      private class FieldTripRouteMetadata
      {
          [Required]
          [DisplayFormat(DataFormatString = "{0:d}")]
          public DateTime Date { get; set; }
  
          [Required]
          [DisplayName("Route")]
          public int RouteID { get; set; }
  
          [Required]            
          [DisplayName("Departure Time")]
          [UIHint("TimeWithPeriod")]
          [DisplayFormat(DataFormatString = "{0:h:mm tt}")]
          public DateTime DepartureTime { get; set; }
  
          [Required]
          [StringLength(255)]
          [DisplayName("Pickup Location")] 
          public String PickupLocation { get; set; }
  
          [Required]
          [StringLength(255)]
          public String Destination { get; set; }
  
          [Required]            
          [DisplayName("Arrival Time")]
          [UIHint("TimeWithPeriod")]
          [DisplayFormat(DataFormatString = "{0:h:mm t}")]
          public DateTime ArrivalTime { get; set; }
  
          public bool IsReturnRoute { get; set; }
  
          public int FieldTripID { get; set; }
      }
  </code></pre>
  
  <p>and my Editor Template:</p>
  
  <pre><code>@model FieldTripRoute
  
  @{string routeType = (Model.IsReturnRoute ? "return" : "");}
  
  &lt;fieldset class="add@(routeType)Route" style="clear: both; width: 620px; margin-right: auto; margin-left: auto;"&gt;
      &lt;legend&gt;Add Route&lt;/legend&gt;
      &lt;div style="float: left; width: 275px;"&gt;
          &lt;div&gt;
              &lt;div class="editor-label"&gt;@Html.LabelFor(model =&gt; model.Date)&lt;/div&gt;
              &lt;div class="editor-field"&gt;@Html.EditorFor(model =&gt; model.Date)&lt;/div&gt;
              &lt;div class="validation-error"&gt;@Html.ValidationMessageFor(model =&gt; model.Date)&lt;/div&gt;
          &lt;/div&gt;
          &lt;div&gt;
              &lt;div class="editor-label"&gt;@Html.LabelFor(model =&gt; model.DepartureTime)&lt;/div&gt;
              &lt;div class="editor-field"&gt;@Html.EditorFor(model =&gt; model.DepartureTime)&lt;/div&gt;
              &lt;div class="validation-error"&gt;@Html.ValidationMessageFor(model =&gt; model.DepartureTime)&lt;/div&gt;
          &lt;/div&gt;
          &lt;div&gt;
              &lt;div class="editor-label"&gt;@Html.LabelFor(model =&gt; model.ArrivalTime)&lt;/div&gt;
              &lt;div class="editor-field"&gt;@Html.EditorFor(model =&gt; model.ArrivalTime)&lt;/div&gt;
              &lt;div class="validation-error"&gt;@Html.ValidationMessageFor(model =&gt; model.ArrivalTime)&lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
      &lt;div style="float: left;"&gt;
          &lt;div&gt;
              &lt;div class="editor-label"&gt;@Html.LabelFor(model =&gt; model.RouteID)&lt;/div&gt;
              &lt;div class="editor-field"&gt;@Html.DropDownListFor(model =&gt; model.RouteID, Model.EditRouteList)&lt;/div&gt;
              &lt;div class="validation-error"&gt;@Html.ValidationMessageFor(model =&gt; model.RouteID)&lt;/div&gt;
          &lt;/div&gt;
          &lt;div&gt;
              &lt;div class="editor-label"&gt;@Html.LabelFor(model =&gt; model.PickupLocation)&lt;/div&gt;
              &lt;div class="editor-field"&gt;@Html.TextBoxFor(model =&gt; model.PickupLocation)&lt;/div&gt;
              &lt;div class="validation-error"&gt;@Html.ValidationMessageFor(model =&gt; model.PickupLocation)&lt;/div&gt;
          &lt;/div&gt;
          &lt;div&gt;
              &lt;div class="editor-label"&gt;@Html.LabelFor(model =&gt; model.Destination)&lt;/div&gt;
              &lt;div class="editor-field"&gt;@Html.EditorFor(model =&gt; model.Destination)&lt;/div&gt;
              &lt;div class="validation-error"&gt;@Html.ValidationMessageFor(model =&gt; model.Destination)&lt;/div&gt;
          &lt;/div&gt;          
      &lt;/div&gt;        
      &lt;div style="clear: both; width: 100px; margin: 20px auto 0 auto;"&gt;
          &lt;input type="button" id="submit@(routeType)Form" name="submit@(routeType)Form" value="Add" /&gt;
      &lt;/div&gt;
  &lt;/fieldset&gt;
  </code></pre>
  
  <p>And my viewModel:</p>
  
  <pre><code>public class FieldTripEditViewModel
  {
      public FieldTrip Trip { get; set; }        
      public FieldTripRoute Route { get; set; }        
      public FieldTripRoute ReturnRoute { get; set; }
  
      public FieldTripEditViewModel(){}
  
      public FieldTripEditViewModel(FieldTrip trip)
      {
          this.Trip = trip;
          this.Route = new FieldTripRoute();
          this.ReturnRoute = new FieldTripRoute {IsReturnRoute = true};
      }
  }
  </code></pre>
  
  <p>I looked at <a href="https://stackoverflow.com/questions/5378520/asp-net-mvc-3-client-side-unobtrusive-validation-for-editor-templates">this post</a> and all of my base editor templates correspond to the idea of leaving the name as an empty string to allow MVC to generate it. Yet I still have no validation.</p>