title: ASP.NET MVC Displaying errors through ModelState.AddModelError in partial view
body: <p>In a cab reservation system using MVC 4, I am using a partial view in Home->Index to display a Quick Book section. In the layout, I am using the following code to render the partial view:</p>
  
  <pre><code>    @{Html.RenderAction("CategoryMenu", "Search");} 
  </code></pre>
  
  <p>The CategoryMenu action of the SearchController is:</p>
  
  <pre><code>   [ChildActionOnly]
      public ActionResult CategoryMenu()
      {
          var searches = new QuickSearch();
          return PartialView(searches);
      }
  </code></pre>
  
  <p>The QuickSearch model is:</p>
  
  <pre><code>public class QuickSearch
  {
      public int CatId { get; set; }
  
      [DisplayName("Pickup date")]
      [Required(ErrorMessage = "Pickup Date is  required.")]       
      public string PickupDate { get; set; }
  
      [DisplayName("Cab Type")]
      [Required(ErrorMessage = "Category  is  required.")]
      public int CabCategory{ get; set; }
  
  
      public static IEnumerable&lt;Category&gt; Categories = new List&lt;Category&gt; { 
  new Category {
      CategoryId = 1,
      Name = "Economy"
  },
  new Category {
      CategoryId = 2,
      Name = "Midsize"
  },
  /*Other categories*/
  };
  }
  </code></pre>
  
  <p>And finally in the partial view of the CategoryMenu.cshtml file I am sending the QuickSearch model to a SearchByDate action of SearchController. In the SearchByDate action, I want to ensure that the Pickup date is not earlier than the current date. I have created a AppHelper.CheckDate() method to validate the requirement. 
  However, I am not being able to display the error message for an earlier Pickup date in the partial view present in the Home Index. In the SearchByDate action, I tried the following:</p>
  
  <pre><code>if (!AppHelper.CheckDate(model.PickupDate))
         {
  
             ModelState.AddModelError("", "Date cannot be before the current date.");
             return PartialView("CategoryMenu");
  
         }
  </code></pre>
  
  <p>However, the entire CategoryMenu view is getting displayed with the error message instead of the error message that should get displayed in the partial view of the Home Index. Any help will be appreciated.</p>