开发者

best way to handle and display Status / Error messages in MVC?

开发者 https://www.devze.com 2022-12-10 20:47 出处:网络
What patterns are people using to display status messages and error messages to users in Asp.Net MVC?

What patterns are people using to display status messages and error messages to users in Asp.Net MVC?

I currently use ModelState.AddModelError for problems with adding / editing / updating objects but what about after that? Say a status message's to let them know their action ran correctly?

Was thinking开发者_StackOverflow社区 about using TempData since alot of times a re-direct is involved.

Anyone have a good pattern they are using that works well?


I use ModelState.AddModelError for error messages and TempData for success messages. I have the following code on my master page so that any time TempData["SucessMessage"] is defined, the success message will be displayed to the user on top of the page:


I've been using the built in Html helpers (Html.ValidationSummary(), Html.ValidationMessage()) along with xVal to display all validation messages. I then use TempData to display all other status messages to the user.

0

精彩评论

暂无评论...
验证码 换一张
取 消