title: asp mvc error :Object reference not set to an instance of an object when validation
body: <pre><code>[AcceptVerbs(HttpVerbs.Post)]   
  public ActionResult Create([Bind(Exclude = "Id")]CustomerInfo customerinfo)
  
  {
  
     if (customerinfo.FirstName.Trim().Length == 0)
         ModelState.AddModelError("FirstName", "First name is required.");
     if (customerinfo.LastName.Trim().Length == 0)
         ModelState.AddModelError("LastName", "Last name is required.");
     if (customerinfo.Phone.Length &gt; 0 &amp;&amp; !Regex.IsMatch(customerinfo.Phone, @"((\(\d{3}\) ?)|(\d{3}-))?\d{3}-\d{4}"))
         ModelState.AddModelError("Phone", "Invalid phone number.");
     if (customerinfo.Email.Length &gt; 0 &amp;&amp; !Regex.IsMatch(customerinfo.Email, @"^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$"))
         ModelState.AddModelError("Email", "Invalid email address.");
     if (!ModelState.IsValid)
         return View();
     try
     {
          BLL.Customer customer = new BLL.Customer();
          customer.CreateCustomer(customerinfo);
  
          return RedirectToAction("Index");
  
      }
      catch
      {
          return View();
      }
  }
  </code></pre>