Best Way to display a user friendly error message for the users, when an DBupdateexception occurred
问题 I have the following code inside my action method : Try { repository.Save(); DetailBox b = new DetailBox() { Tag = repository.getTechnologyTagByIT360ID(resourceid) }; return PartialView("_detailBox", b); } catch (DbUpdateException e) { ModelState.AddModelError(string.Empty, "Error occurred:" + e.InnerException.InnerException.Message); } Currently, if the DbUpdatException occurs it will show the following error to the user: • Error occurred: Violation of UNIQUE KEY constraint 'IX_Technology_2'