public async Task <IActionResult> Create(PagesListViewModel model) { var checkStub = new Regex(@"^[\w\-]*$"); if (!checkStub.IsMatch(model.PageHeader.Stub)) { ModelState.AddModelError("PageHeader.Stub", "Invalid stub, only letters, numbers, hypens and underscores are allowed"); } if (ModelState.IsValid) { try { var pageHeader = await _pageService.AddPageHeaderAsync(model.PageHeader); ShowAlertSuccess($"Page \"{pageHeader.PageName}\" created!"); return(RedirectToAction(nameof(Detail), new { id = pageHeader.Id })); } catch (GraException gex) { AlertInfo = gex.Message; } } else { var errorMessages = new StringBuilder("<ul>"); foreach (var error in ModelState.Values.SelectMany(_ => _.Errors)) { errorMessages.Append("<li>").Append(error.ErrorMessage).Append("</li>"); } errorMessages.Append("</ul>"); ShowAlertDanger("Could add the page to the following error(s):", errorMessages.ToString()); } return(RedirectToAction(nameof(Index), new { page = model.PaginateModel.CurrentPage })); }