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

  • Home
  • SEARCH
  • 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 7547537
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T09:28:42+00:00 2026-05-30T09:28:42+00:00

Post updated to reflect partial fix suggested by @Kate. Original post below new post:

  • 0

Post updated to reflect partial fix suggested by @Kate. Original post below new post:

I have Ajax call to HttpPost Action method. If the method executes without exception, I want it load its data as a partial view in a div element (it does this successfully). If there is an exception, I want it to load the asp mvc Error view as a full page view. However, with the code below, an exception causes the Error view to load as partial view in said div element. I must be leaving something out of my controller…

[HttpPost]
[HandleError]
public ActionResult LoadUnmappedProjects()
{
    bool error = false;
    try
    {
        throw new ArgumentException();
    }
    catch (Exception e)
    {
        error = true;
    }

    if (!error)
        using (var db = new prismEntities())
        {
            return PartialView(db.dmPSPProjectStatewideRegionals.ToList());
        }
    else
    {
        return View("Error");
    }   
}

Ideas???

ORIGINAL POST

In an ASP MVC3 web app, I have an ajax call to and [HttpPost] action method. The method hits a database and return data to a partial view. If the database or the table of interest is down, I’d like to return the Error view. But I can’t seem to combine [HttpPost] and [HandleError] on the method to effect this:

    [HttpPost]
    [HandleError]
    public ActionResult LoadUnmappedProjects()
    {

        try
        {
            throw new ArgumentException();
        }
        catch (Exception e)
        {
            throw new CustomDbException(e);
        }

        using (var db = new prismEntities()){
        return PartialView(db.dmPSPProjectStatewideRegionals.ToList());
        }


    }

The stock Error.cshtml doesn’t get rendered. Instead, an error gets returned to the Ajax call, and currently I’m just popping up an alert(). Is there some thing I can do to the method above to cause the Error view to render? Or should I use the error returned in the Ajax call to somehow render the Error view?

Here is my ajax call:

$.ajax({
    url: pathLoadUnmappedProjects,
    type: 'POST',
    dataType: 'html',
    contentType: 'application/json; charset=utf-8',
    success: function (result) {
        $('#unmappedProjects').html(result);
    },

    error: function () {

        alert("Error:");
    }
});
  • 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-30T09:28:43+00:00Added an answer on May 30, 2026 at 9:28 am

    The problem is in your code. Because you throw the exception it automatically stop the process and return 500 Error server (you can check the Net tab in your Firebug to see it). So, my suggestion is not to throw exception here:

    throw new ArgumentException();
    
    You can something like that:
    try
    {
         ...
    }
    catch (Exception e)
    {
        error = true;
    }
    if (error)
    {
    // render Error page
    }
    

    If you need to redirect to some page just try to return the page name what you want to redirect to and do it in JS code as described here: How to reload page when an ajax request returns FormsAuthentication.RedirectToLoginPage?

    So you code will looks like:

    error: function () {
    
            window.location.href = "Error/Index";
        }
    

    In this case you can throw exception as you did before and the ajax code will catch error response and redirect.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

UPDATED See post #3 below. There is a need to upload a file to
UPDATE: I should have mentioned in the original post that I want to learn
On my forum-based website, I have a link below every post for reporting spam
I have deleted my previous question and post this updated: I have a an
Update: This turned into a blog post, with updated links and code, over at
I'm using jquery ajax to post updates back to my server. I'm concerned about
I've a client testing the full text (example below) search on a new Oracle
We have application settings derived from ApplicationSettingsBase . When we push a new version
This is my first attempt at adding ajax to a WordPress plugin. I have
scenario: I want to do an ajax call to update the image shown. Example:

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.