public JsonResult Save(Customer customer) { try { if (customer.CustomerId <= 0) { throw new Exception("Invalid Id."); } else if (customer.CustomerName.Trim() == "") { throw new Exception("Customer Name Required."); } else if (customer.Address.Trim() == "") { throw new Exception("Customer Address Required."); } DataSet.AddCustomer(customer); var x = DataSet.GetAllCustomer(); x.Add(customer); var t = Session["Data"]; Session["Data"] = x; } catch (Exception e) { Response.StatusCode = (int)HttpStatusCode.Forbidden; Response.StatusDescription = e.Message.ToString(); } return(Json(customer, JsonRequestBehavior.AllowGet)); }