public ActionResult DisplayFormEvent(EventViewModel model) { // If everything is valid, then set ModelStateIsValid = true; so javaScript will redirect to Index() action which will populate this newly created event inside of calendar. // else if something has failed, Add error message // In both cases redirect to partial view. if (model != null && ModelState.IsValid) { if (model.End.HasValue && model.Start.HasValue && DateTime.Compare(model.Start.Value, model.End.Value) <= 0) { if (string.IsNullOrEmpty(model.Id)) { // Add new event. eventsCategoryList.Add (new CategoryItemViewModel() { Id = new Random().Next(20, 1000).ToString(), EventDescription = new ContentViewModel().AddText(model.Description), Title = model.Title, Start = model.Start, End = model.End, AllDay = model.AllDay } ); } else { // Edit existing event. var eventToUpdate = GetAppointment(model.Id); if (eventToUpdate != null) { eventToUpdate = model.ToCategoryItemViewModel(eventToUpdate); eventsCategoryList.Remove(eventToUpdate); eventsCategoryList.Add(eventToUpdate); } } model.ModelStateIsValid = true; } else { AddErrorMessage("End", "End Session must occur later than Start Session."); } } else if (model == null) { AddErrorMessage("Model is null."); return(Content(string.Empty)); } return(PartialView("EditorTemplates/Object", model)); }