Note that there are some explanatory texts on larger screens.

plurals
  1. POASP.NET MVC - Approach for global error handling?
    primarykey
    data
    text
    <p>I was wondering what the best implementation for a global error (doesn't have to be errors, can also be success messages) handler would be? Let me break it down for you with an example:</p> <ol> <li>User tries to delete a record </li> <li>Deletion fails and an error is logged</li> <li>User redirects to another page</li> <li>Display error message for user (using a HtmlHelper or something, don't want it to be a specific error page)</li> </ol> <p>I'm just curious what you guys think. I've been considering TempData, ViewData and Session but they all have their pros and cons.</p> <p>TIA!</p> <p><strong>UPDATE:</strong></p> <p>I'll show an example what I exactly mean, maybe I wasn't clear enough. This is an example of a method that adds a message when user deletes a record. If user succeeds, user redirects to another page</p> <pre><code>public ActionResult DeleteRecord(Record recordToDelete) { // If user succeeds deleting the record if (_service.DeleteRecord(recordToDelete) { // Add success message MessageHandler.AddMessage(Status.SUCCESS, "A message to user"); // And redirect to list view return RedirectToAction("RecordsList"); } else { // Else return records details view return View("RecordDetails", recordToDelete); } } </code></pre> <p>And in the view "RecordsList", it would be kinda cool to show all messages (both error and success messages) in a HtmlHelper or something.</p> <pre><code>&lt;%= Html.RenderAllMessages %&gt; </code></pre> <p>This can be achieved in many ways, I'm just curious what you guys would do. </p> <p><strong>UPDATE 2:</strong></p> <p>I have created a custom error (message) handler. You can see the code if you scroll down.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload