public ActionResult AddCustomer(CustomerViewModel model) { DataTable dt = new DataTable(); if (Helper.SessionHelper.GetCurrentUserID() == 0) { return(RedirectToAction("Registration", "Account")); } try { if (ModelState.IsValid) { if (model.Fileupload != null) { var supportedTypes = new[] { "csv" }; var fileExt = System.IO.Path.GetExtension(model.Fileupload.FileName).Substring(1); if (!supportedTypes.Contains(fileExt)) { model.ErrorCode = "Error"; model.ErrorMessage = "File Extension Is InValid - Only Upload CSV File"; } else { string fileName = Path.GetFileName(model.Fileupload.FileName); int fileSize = model.Fileupload.ContentLength; int Size = fileSize / 1000000; string filetype = model.Fileupload.ContentType; model.Fileupload.SaveAs(Server.MapPath("~/CustomerFileUpload/" + fileName)); string path = Server.MapPath("~/CustomerFileUpload/" + fileName); model.ImportCustomer(path); } } } if (model.ErrorCode == "Error") { TempData["ErrorMessage"] = model.ErrorMessage; TempData["ErrorCode"] = model.ErrorCode; } else { TempData["ErrorMessage"] = "File Import Successfully"; TempData["ErrorCode"] = "Success"; } return(RedirectToAction("CustomerList")); } catch (Exception ex) { ex.Message.ToString(); return(Content("An error occurred")); } }