Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6346943
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T21:06:53+00:00 2026-05-24T21:06:53+00:00

I was wondering what the best implementation for a global error (doesn’t have to

  • 0

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:

  1. User tries to delete a record
  2. Deletion fails and an error is logged
  3. User redirects to another page
  4. Display error message for user (using a HtmlHelper or something, don’t want it to be a specific error page)

I’m just curious what you guys think. I’ve been considering TempData, ViewData and Session but they all have their pros and cons.

TIA!

UPDATE:

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

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);
    }
}

And in the view “RecordsList”, it would be kinda cool to show all messages (both error and success messages) in a HtmlHelper or something.

<%= Html.RenderAllMessages %>

This can be achieved in many ways, I’m just curious what you guys would do.

UPDATE 2:

I have created a custom error (message) handler. You can see the code if you scroll down.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T21:06:54+00:00Added an answer on May 24, 2026 at 9:06 pm

    I’m confused by these steps:

    • Deletion fails and an error is logged
    • User redirects to another page

    Why would you redirect the User when an error occurs? That doesnt make any sense, unless im misunderstanding something.

    Generally, i follow these guidelines:

    • Error with form submission (e.g HTTP POST): check ModelState.IsValid and return the same View and render the error out with @Html.ValidationSummary()
    • Error with AJAX call: return JsonResult (like @Tomas says), and use basic client-side scripting to inspect the JSON and show the result
    • Error with domain/business: throw custom exceptions and let the controller catch them and add to ModelState as above
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just wondering what the best practise advice would be on the architecture for a
I am wondering what other people have found to be the best graphing libraries/plug-ins/gems
I was wondering what is the standard/best implementation of that in Java NIO. This
I'm wondering the best way to start a pthread that is a member of
I was wondering the best way to upload file to a web server in
I'm fairly new to Visual Studio and am wondering how best to plan for
I'm new to web development and am just wondering about best practices for java
I am writing a simple multithreaded socketserver and I am wondering how best to
I'm new to SQL Server Reporting Services, and was wondering the best way to
Just wondering where is best to put functionality in an MFC application that is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.