public ActionResult Add(Vehicles model) { if (model.Id == 0) { ModelState["Id"].Errors.Clear(); ModelState["VehicleSpecs.ModelId"].Errors.Clear(); ModelState["VehicleStatus.VehicleId"].Errors.Clear(); ModelState["VehicleStatus.BatteryStatus"].Errors.Clear(); ModelState["VehicleStatus.InRide"].Errors.Clear(); //ModelState["VehicleStatus.InService"].Errors.Clear(); } if (ModelState.IsValid) { string fileName = ""; string fileName2 = ""; foreach (string file in Request.Files) { var fileContent = Request.Files[file]; if (fileContent != null && fileContent.ContentLength > 0) { fileName = Path.GetFileName(fileContent.FileName); fileName = Guid.NewGuid().ToString().Substring(0, 6).ToString() + fileName; // Add file var path = Path.Combine(Server.MapPath("~/DataImages/"), fileName); fileContent.SaveAs(path); } } if (!string.IsNullOrEmpty(fileName)) { model.ImageName = fileName; } if (!string.IsNullOrEmpty(fileName2)) { model.UniqueId = fileName2; } using (VehicleRepository areaProxy = new VehicleRepository()) { reqResponse = areaProxy.AddUpdate(model); return(Json(reqResponse, JsonRequestBehavior.AllowGet)); } } else { reqResponse.ErrorMessages.Add("invalidData", OperationLP.InvalidData); return(Json(reqResponse, JsonRequestBehavior.AllowGet)); } }