public ActionResult Create(Models.vmBatch batchModel) { var batch = GetBatch(batchModel); try { if (ModelState.IsValid) { if (BatchRepo.Create(batch) == true) { ViewData["SuccessMsg"] = "Batch created successfully."; return(Redirect("/")); } else { ViewData["ErrorMsg"] = "The Batch already exists with the same name."; } } } catch (Exception) { ViewData["ErrorMsg"] = "Failed to create batch."; } var TrainerList = TrainerRepo.GetAll(); ViewBag.Trainers = new SelectList(TrainerList, "Id", "Name"); var vmBatch = new Models.vmBatch { //BatchDates = batch.BatchDates.Select(p=> DateTime.ParseExact(p, "mm/dd/yyyy", null)). Id = batch.Id, Name = batch.Name, trainer = batch.trainer, TrainerId = batch.TrainerId }; return(View(vmBatch)); }