title: Is it possible to validate an MVC-3 model without validating "sub-models"?
body: <p>I have a class that requires another class to be specified, but I don't want the MVC ModelState validator to check whether the secondary model is valid.  Is this possible?</p>
  
  <p>Here's a brief overview:</p>
  
  <p>My entities look something like this:</p>
  
  <pre><code>public class WidgetType
  {
      public long Id { get; private set; }
  
      [Required]
      public string Name { get; set; }
  
      ...
  }
  
  public class Widget
  {
      public long Id { get; private set; }
  
      [Required]
      public string Name { get; set; }
  
      [Required]
      public WidgetType WidgetType { get; set; }
  
      ...
  }
  </code></pre>
  
  <p>I have them encapsulated in a <code>WidgetViewModel</code> class that I'm passing to/from the View like this:</p>
  
  <pre><code>public class WidgetViewModel
  {
      public Widget Widget { get; set; }
  
      public ICollection&lt;WidgetType&gt; WidgetTypes
      {
          get
          {
              return _repository.GetWidgets();
          }
      }
  
      ...
  }
  </code></pre>
  
  <p>My view looks something like this:</p>
  
  <pre><code>...
  @Html.DropDownListFor( m =&gt; m.Widget.WidgetType.Id, new SelectList( new EquipmentViewModel().EquipmentTypes, "Id", "Name" ) )
  ...
  </code></pre>
  
  <p>All of this works except for validation.  <code>ModelState.IsValid</code> is always false because <code>"Widget.WidgetType.Name"</code> is required.  I need the user to select a <code>WidgetType</code>, but I don't want ModelState to be validated deeper than "Widget.WidgetType.Id" (which should be all that <code>Widget</code> needs for its foreign key?).</p>
  
  <p>Is there a better way to do this?  I feel like there should be some way to validate without recursively inspecting deeper into the properties, but I can't find it.  What am I missing...?</p>