/// <summary> /// Output error messages to ModelState /// </summary> /// <param name="controller">Current Controller</param> public static void OutputModelMessage(this AbpController controller) { if (controller.TempData["ModelState"] != null) { controller.ViewBag.HasMessage = true; var dics = controller.TempData["ModelState"] as ModelStateDictionary; if (dics != null) { var msd = dics.Dereference <ModelStateDictionary>(); foreach (var item in msd) { if (item.Value != null) { foreach (var error in item.Value.Errors) { var strKey = item.Key; if (string.IsNullOrEmpty(strKey)) { strKey = Md5Cipher.GetMd5Str(error.ErrorMessage); } if (!controller.ModelState.ContainsKey(strKey)) { controller.ModelState.AddModelError(strKey, error.ErrorMessage); } } } } } } }