コード例 #1
0
        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));
        }
コード例 #2
0
 public ActionResult General(EditFormItem item)
 {
     if (ModelState.IsValid)
     {
         // DoSomething()
     }
     return(View(item));
 }
コード例 #3
0
        public ActionResult EditFormUpdatePartial(EditFormItem item)
        {
            if (ModelState.IsValid)
            {
                EditFormItems.Update(item);
            }
            else
            {
                ViewData["EditError"] = "Please, correct all errors.";
            }

            return(EditFormPartial());
        }