public ActionResult CreatePost() { var currentUser = (User) Session["CurrentUser"]; var taskList = new TaskList { Owner = currentUser }; try { TryUpdateModel(taskList); // Check if a tasklist already exists with the same title. var existingTaskList = _taskListsService.Get(t => t.PartitionKey == currentUser.RowKey && t.Title == taskList.Title); if (existingTaskList != null) { ViewBag.ValidationErrors = new List<ValidationResult> { new ValidationResult(string.Format("The taskList with the title '{0}' already exists.", taskList.Title)) }; return View(taskList); } if (taskList.IsValid()) { _taskListsService.Create(taskList); return RedirectToAction("Index"); } else { ViewBag.ValidationErrors = taskList.GetValidationErrors(); } } catch (Exception ex) { ViewBag.ValidationErrors = new List<ValidationResult> { new ValidationResult(string.Format("Create taskList exception: {0}", ex.Message)) }; } return View(taskList); }