public ActionResult FormWithErrorMessage(EditFormItem item) { if (ModelState.IsValid) { try { // DoSomething() throw new InvalidOperationException("Some sensitive information"); } catch (Exception ex) { // Unsafe approach - showing an Exception text // ViewData[UpdateStatusKey] = ex.Message; // Safe approach - showing text without sensitive information if (ex is InvalidOperationException) { ViewData[UpdateStatusKey] = "Some error occured..."; } else { ViewData[UpdateStatusKey] = "General error occured..."; } } } else { ViewData[UpdateStatusKey] = "Please, correct all errors."; } return(View(item)); }
public ActionResult General(EditFormItem item) { if (ModelState.IsValid) { // DoSomething() } return(View(item)); }
public ActionResult EditFormUpdatePartial(EditFormItem item) { if (ModelState.IsValid) { EditFormItems.Update(item); } else { ViewData["EditError"] = "Please, correct all errors."; } return(EditFormPartial()); }