title: MVC Data Annotation - Required Field not Working
body: <p>Hi I have the following cod throughout my app but with just two fields it's not working.</p>
  
  <pre><code>[Required]        
  public string DevelopmentPM { get; set; }
  </code></pre>
  
  <p>The following test runs and passes:</p>
  
  <pre><code>    [TestMethod]
      public void SiteConstruction_MODEL_DevelopmentPM_Is_Required()
      {
          //arrange
          var propertyInfo = typeof(SiteConstructionMetadata).GetProperty    
                             ("DevelopmentPM");
  
          //act
          var attribute = propertyInfo.GetCustomAttributes(typeof(RequiredAttribute), 
                          true).Cast&lt;RequiredAttribute&gt;().FirstOrDefault();
  
          //assert
          Assert.IsNotNull(attribute);
      }
  </code></pre>
  
  <p>My controlller looks like:</p>
  
  <pre><code>        TryUpdateModel(siteConstruction);
  
          if (!ModelState.IsValid)
             return View(siteConstruction);
  </code></pre>
  
  <p>I have other required fields in model and they are OK.  This field is null (I checked) but doesn't make the model invalid - so no validation and an error on save.</p>
  
  <p>My View </p>
  
  <pre><code>    &lt;li&gt;
          &lt;label for="DevelopmentPM"&gt;
              &lt;strong&gt;Development PM:&lt;/strong&gt;&lt;/label&gt;
          &lt;%= Html.TextBox("DevelopmentPM") %&gt;
          &lt;%= Html.ValidationMessage("DevelopmentPM", "*") %&gt;
      &lt;/li&gt;
  </code></pre>
  
  <p>I've looked at my .dbml (Linq to SQl), spelling looks ok.</p>
  
  <p>I'm I missing something simple - please, going mad.</p>
  
  <p>Thanks</p>
  
  <p>Davy</p>