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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:31:46+00:00 2026-05-22T12:31:46+00:00

How can I show a div with information whenever an exception occurs when executing

  • 0

How can I show a div with information whenever an exception occurs when executing my action?

Here is what I have so far:

<div id="dvErrorMsg">
    <a href="#" class="close">[x]</a>
    <p>
        <label id="errorMessage">
        </label>
    </p>
</div>

<script type="text/javascript">
        $(function () {

            $("#click_here").click(function (event) {
                event.preventDefault();
                $("#dvErrorMsg").slideToggle();
            });

            $("#dvErrorMsg a").click(function (event) {
                event.preventDefault();
                $("#dvErrorMsg").slideUp();
            });
        });
</script>

And I have this action in my controller:

public ActionResult Validatecall()
{
    //if any exeption happen show div with the custom error
}

How can I catch any exception and send the message back in the AJAX response?

  • 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-22T12:31:47+00:00Added an answer on May 22, 2026 at 12:31 pm

    You can try returning a JavaScriptResult in this case that will tell your div to expand:

    public ActionResult Validatecall()
    {
        ActionResult result;
        try
        {
           // do whatever
        }
        catch (Exception)
        {
           result = JavaScript("$('#dvErrorMsg').show();$('#errorMessage').val(/* Put exception message here*/")");
        }
        return result;
    }
    

    Generally, I would not recommend using this way to interact with the view as you now introduce a dependency into the controller on the view itself as explained here. I offered it as a way to do it since I do not know exactly how you are calling this action.

    Assuming you are calling this action using an ajax call like post I would return a JsonResult indicating if an exception occurred and pass the error message back that way:

    $.post("urltoaction", function (result) {    
       if (result.success)
       {
          // do whatever
       }
       else
       {
         //exception occurred show errors
         $('#dvErrorMsg').show();
         $('#errorMessage').val(result.exceptionMsg);
       }  
    });
    

    Here is the controller code now:

     public ActionResult Validatecall()
     {
            ActionResult result;
            try
            {
              // do whatever
            }
            catch (Exception e)
            {
               result = new JsonResult()
                        {
                            Data = new { success = false, exceptionMsg = e.Message },
                            JsonRequestBehavior = JsonRequestBehavior.AllowGet
                        };
            }
            return result;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I don't want to have the user install Google Gears so I can show
I have to parse out color information from HTML data. The colors can either
So I have this page here: http://www.eminentmedia.com/development/powercity/ As you can see when you mouse
I'm using jQuery to extend a div to show more information (which is in
In Prototype I can show a loading... image with this code: var myAjax =
With this code I can show an animated gif while the server script is
We need a user control that can show Microsoft Office files (Word, Excel..). There
I've always been curious to see if I can show, hide or change a
I've been trying to find a good video that I can show at a
I'm simply trying to create a UML diagram where I can show the header

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.