title: What is ModelState.IsValid valid for in ASP.NET MVC in NerdDinner?
body: <p>On the <a href="http://www.wrox.com/WileyCDA/Section/id-321793.html" rel="noreferrer">NerdDinner</a> example of <a href="http://www.wrox.com/WileyCDA/WroxTitle/Professional-ASP-NET-MVC-1-0.productCd-0470384611.html" rel="noreferrer">Professional ASP.NET MVC 1.0</a> there's a method to create a new dinner as copied bellow (page 89 of the free NerdDinner version).</p>
  
  <p>There it checks ModelState.IsValid for true. It seems to check if the model is valid for the database (that is, it catches data type conversions, like dates with invalid format, but not business rules). Is that true?</p>
  
  <p>When submitting the form, if you have an error in the date, ModelState.IsValid will be false and you'll get back an error, but only for the date because AddRuleViolations was never executed. If you remove the check for ModelState.IsValid completely, then you'll get all the errors (due to the exception), including a marking in the date when it is invalid. Then, why is the check for ModelState.IsValid there at all? Am I missing something?</p>
  
  <pre><code>// 
  // POST: /Dinners/Create 
  
  [AcceptVerbs(HttpVerbs.Post)] 
  public ActionResult Create(Dinner dinner) {
      if (ModelState.IsValid) {
          try {
              dinner.HostedBy = "SomeUser"; 
  
              dinnerRepository.Add(dinner);
              dinnerRepository.Save();
  
              return RedirectToAction("Details", new {id = dinner.DinnerID }); 
          } catch {
              ModelState.AddRuleViolations(dinner.GetRuleViolations());
          } 
      } 
      return View(dinner); 
  } 
  </code></pre>