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 8901145
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T01:16:31+00:00 2026-06-15T01:16:31+00:00

I am creating my first ASP.NET MVC2 Project with using jquery and ajax on

  • 0

I am creating my first ASP.NET MVC2 Project with using jquery and ajax on client side.

Now when i was having Q.A testing the application and add some test exception and pass it to json from my controller that something like this:

Controller:

public JsonResult PopulateDetails(int id)
        {
                  ProductServiceClient client = new ProductServiceClient();
            try
            {
                if (id == 0)
                { throw new Exception("TEST ERROR."); }

                string name= "test";
                List<Product> product= client.GetPriductbyName(name);
                return Json(product);

            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

Jquery-Ajax Script:

$.ajax({
        type: "POST",
        url: url_ ,
        data: search,
        success: function(data) {   // data: Passed (Records) from the PopulateDetails controller
            displayDetails(data);   // after routing on Populate Details  converts the data to table
        },
        error: function(XMLHttpRequest, textStatus, errorThrown) {
            alert("error: " + XMLHttpRequest.responseText);
        },
        dataType: 'json'
    });

I notice that it will return this default error message below:

---------------------------
Windows Internet Explorer
---------------------------
error: <html>

    <head>

        <title>TEST ERROR.</title>

        <style>

         body {font-family:"Verdana";font-weight:normal;font-size: .7em;color:black;} 

         p {font-family:"Verdana";font-weight:normal;color:black;margin-top: -5px}

         b {font-family:"Verdana";font-weight:bold;color:black;margin-top: -5px}

         H1 { font-family:"Verdana";font-weight:normal;font-size:18pt;color:red }

         H2 { font-family:"Verdana";font-weight:normal;font-size:14pt;color:maroon }

         pre {font-family:"Lucida Console";font-size: .9em}

         .marker {font-weight: bold; color: black;text-decoration: none;}

         .version {color: gray;}

         .error {margin-bottom: 10px;}

         .expandable { text-decoration:underline; font-weight:bold; color:navy; cursor:hand; }

        </style>

    </head>



    <body bgcolor="white">



            <span><H1>Server Error in '/' Application.<hr width=100% size=1 color=silver></H1>



            <h2> <i>TEST ERROR.</i> </h2></span>



            <font face="Arial, Helvetica, Geneva, SunSans-Regular, sans-serif ">



            <b> Description: </b>An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.



            <br><br>



            <b> Exception Details: </b>System.Exception: TEST ERROR.<br><br>



            <b>Source Error:</b> <br><br>



            <table width=100% bgcolor="#ffffcc">

               <tr>

                  <td>

                      <code><pre>



Line 64:             catch (Exception ex)

Line 65:             {

<font color=red>Line 66:                 throw ex;

</font>Line 67:             }

Line 68:         }</pre></code>



                  </td>

               </tr>

            </table>



            <br>

---------------------------
OK   
---------------------------

Now how to display just the error message from the exception neatly not the whole html error message. Something like simple as display of an alert message box alert(“TEST ERROR”).

Is there ways how to do it more simpler?

I saw this linked on asp.net which look good How Do I Handle jQuery Errors and Display them on the Client?

but i cant find where AjaxResponseViewModel() came declared.

  • 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-06-15T01:16:32+00:00Added an answer on June 15, 2026 at 1:16 am

    In your catch, you should probably log the error and then return a json friendly result, e.g.

     catch (Exception ex)
     {
          //log.Error(ex); using whatever you use to log
          return Json(ex.Message);
     }
    

    or

    return Json("There has been an error, please contact support or read the log");
    

    Above you are throwing the exception which will return the error view in full.

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

Sidebar

Related Questions

I'm looking at creating my first ASP.NET MVC application using MVC3. The project template
I am creating my first ASP.Net MVC3 Application using Azure as DB Storage. There
I'm creating an ASP.NET MVC application using F# on IIS 7. When I attempt
I have an ASP.NET MVC 3 application using an Entity Framework (4.3.1) Code First
Asp.net MVC2: I have many dropdownlists in my mvc application. At first, I started
As I'm in the process of creating my first ASP.NET MVC 4 Internet application,
I'm creating my first MVC.Net application and I find myself including @using Gideon.Core.Mvc; on
I am creating asp.net web application with web forms, I am using register routes
I am creating my first ASP.NET MVC 3 application, and my data comes from
For my first ASP.NET MVC 3 application, I'm using the aspnet_Users and aspnet_Roles tables

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.