title: How to show ModelState.AddModelError when the Model is Empty in MVC4
body: <p>I am displaying a shopping cart. I need to check for empty values in Shopping cart and display a message like "The Shopping Cart is empty".<br/></p>
  
  <p>When I use ModelState.AddModelError in myAction, it throws an exception as there is null reference in Model. How to display the ErrorMessage.<br/>
  My Action <br/></p>
  
  <pre><code>  public ActionResult Index()
          {
              string id = Request.QueryString["UserID"];
              IList&lt;CartModel&gt; objshop = new List&lt;CartModel&gt;();
              objshop = GetCartDetails(id);
              if (objshop.Count &gt; 0)
              {
                  return View(objshop.ToList());
              }
              else
              {
                  ModelState.AddModelError("", "Your Shopping Cart is empty!");
              }
              return View();
  }
  </code></pre>
  
  <p>My View<br/></p>
  
  <pre><code>    @{
           @Html.ValidationSummary(true)
       }
  
   &lt;th &gt; @Html.DisplayNameFor(model =&gt; model.ProductName) &lt;/th&gt;
   &lt;th &gt; @Html.DisplayNameFor(model =&gt; model.Quantity)   &lt;/th&gt;
   &lt;th &gt; @Html.DisplayNameFor(model =&gt; model.Rate)      &lt;/th&gt;
   &lt;th &gt; @Html.DisplayNameFor(model =&gt; model.Price)    &lt;/th&gt;        
   @foreach (var item in Model)
     {
  &lt;td&gt;  @Html.DisplayFor(modelItem =&gt; item.ProductName)&lt;/td&gt;
  &lt;td&gt;  @Html.DisplayFor(modelItem =&gt; item.Quantity)&lt;/td&gt;
  &lt;td&gt;  @Html.DisplayFor(modelItem =&gt; item.Rate) &lt;/td&gt;
  &lt;td&gt;  @Html.DisplayFor(modelItem =&gt; item.Price) &lt;/td&gt;
     }
  </code></pre>
  
  <p>Any suggestions.</p>