public ActionResult Create(MedicationViewModel medicationViewModel) { medicationViewModel.MedicalRecordEntryViewModel = medicalRecordEntryRepository.GetById((int)TempData["medicalRecordId"]).ToViewModel(); AddMedicalRecordToTempData(medicationViewModel.MedicalRecordEntryViewModel.Id); TempData.Keep(); if (ModelState.IsValid) { AddMedicalRecordToTempData(medicationViewModel.MedicalRecordEntryViewModel.Id); medicationRepository.Add(medicationViewModel.ToDomainModel()); return(RedirectToAction("Index", new { medicalRecordId = medicationViewModel.MedicalRecordEntryViewModel.Id })); } AddMedicalRecordToTempData(medicationViewModel.MedicalRecordEntryViewModel.Id); return(View(medicationViewModel)); }