title: ASP.NET MVC 2 client-side validation rules not being created
body: <p>MVC isn't generating the client-side validation rules for my viewmodel. The HTML just contains  this:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  //&lt;![CDATA[
  if (!window.mvcClientValidationMetadata) { window.mvcClientValidationMetadata = []; }
  window.mvcClientValidationMetadata.push({"Fields":[],"FormId":"form0","ReplaceValidationSummary":false});
  //]]&gt;
  &lt;/script&gt;
  </code></pre>
  
  <p>Note that <code>Fields[]</code> is empty!</p>
  
  <p>My view is strongly-typed and uses the new strongly-typed HTML helpers (<code>TextBoxFor()</code>, etc).</p>
  
  <h2>View Model / Domain Model</h2>
  
  <pre><code>public class ItemFormViewModel
  {
      public Item Item { get; set; }
      [Required] [StringLength(100)] public string Whatever { get; set; } // for demo
  }
  [MetadataType(typeof(ItemMetadata))]
  public class Item
  {
      public string Name { get; set; }
      public string SKU { get; set; }
      public int QuantityRequired { get; set; }
      // etc.
  }
  public class ItemMetadata
  {
      [Required] [StringLength(100)] public string Name { get; set; }
      [Required] [StringLength(50)] public string SKU { get; set; }
      [Range(0, Int32.MaxValue)] public int QuantityRequired { get; set; }
      // etc.
  }
  </code></pre>
  
  <p>(I know I'm using a domain model <em>as my / as part of my</em> view model, which isn't a good practice, but disregard that for now.)</p>
  
  <h2>View</h2>
  
  <pre><code>&lt;%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" 
  Inherits="System.Web.Mvc.ViewPage&lt;ItemFormViewModel&gt;" %&gt;
  
  &lt;asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server"&gt;
      &lt;h2&gt;Editing item: &lt;%= Html.Encode(Model.Item.Name) %&gt;&lt;/h2&gt;
  
      &lt;% Html.EnableClientValidation(); %&gt;
      &lt;%= Html.ValidationSummary("Could not save the item.") %&gt;
  
      &lt;% using (Html.BeginForm()) { %&gt;
  
          &lt;%= Html.TextBoxFor(model =&gt; model.Item.Name) %&gt;
          &lt;%= Html.TextBoxFor(model =&gt; model.Item.SKU) %&gt;
          &lt;%= Html.TextBoxFor(model =&gt; model.Item.QuantityRequired) %&gt;
  
          &lt;%= Html.HiddenFor(model =&gt; model.Item.ItemID) %&gt;
  
          &lt;%= Html.TextBox("Whatever", Model.Whatever) %&gt;
      &lt;input type="submit" value="Save" /&gt;
      &lt;% } %&gt;
  &lt;/asp:Content&gt;
  </code></pre>
  
  <p>I included the <code>Whatever</code> property on the view model because I suspected that MVC wasn't recursively inspecting the sub-properties of <code>ItemFormViewModel.Item</code>, but even that isn't being validated? I've even tried delving into the MVC framework source code but have come up empty. What could be going on?</p>