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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:11:25+00:00 2026-05-27T14:11:25+00:00

Please keep in mind that I’m rather new to how MVC, Json, jQuery, etc.

  • 0

Please keep in mind that I’m rather new to how MVC, Json, jQuery, etc. works, so bear with me. I’ve been doing Web Forms for the past 5 years…

I’m working on validating a form within a Modal popup that uses a JsonResult method for posting the form data to the server. I wish I could have just loaded a Partial View in that popup and be done with it, but that’s not an option.

Anyway, I have some code that was working yesterday, but after I did a pull / push with Git, something went a bit wrong with my validation. I do some basic validation with regular JavaScript before I pass anything to the server (required fields, correct data types, etc.), but some things, like making sure the name the user types in is unique, require me to go all the way to the business logic.

After poking around the internet, I discovered that if you want jQuery to recognize an error from a JsonResult in an AJAX request, you must send along a HTTP Status Code that is of an erroneous nature. I’m fairly certain it can be any number in the 400’s or 500’s and it should work…and it does…to a point.

What I would do is set the Status Code and Status Description using Response.StatusCode and Response.StatusDescription, then return the model. The jQuery would recognize an error, then it would display the error message I set in the status description. It all worked great.

Today, it seems that the only thing that makes it from my JsonResult in my controller to my jQuery is the Status Code. I’ve traced through the c# and everything seems to be set correctly, but I just can’t seem to extract that custom Status Description I set.

Here is the code I have:

The Modal Popup

<fieldset id="SmtpServer_QueueCreate_Div">
    @Form.HiddenID("SMTPServerId")
    <div class="editor-label">
        @Html.LabelFor(model => model.ServerName)
        <br />
        <input type="text" class="textfield wide-box" id="ServerName" name="ServerName" title="The display name of the Server" />
        <br />
        <span id="ServerNameValidation" style="color:Red;" />
    </div>
    <div class="editor-label">
        <span id="GeneralSMTPServerValidation" style="color:Red;" />
    </div>
    <br />
    <p>
        <button type="submit" class="button2" onclick="onEmail_SmtpServerQueueCreateSubmit();">
        Create SMTP Server</button>
        <input id="btnCancelEmail_SmtpServerQueueCreate" type="button" value="Cancel" class="button"
        onclick="Email_SmtpServerQueueCreateClose();" />
    </p>
</fieldset>

The Controller

    [HttpPost]
        public virtual JsonResult _QueueCreate(string serverName)
        {
            Email_SmtpServerModel model = new Email_SmtpServerModel();
            string errorMessage = "";
            try
            {
                Email_SmtpServer dbESS = new Email_SmtpServer(ConnectionString);
                model.SMTPServerId = System.Guid.NewGuid();
                model.ServerName = serverName;
                if (!dbESS.UniqueInsert(model, out errorMessage))
                {
                    return Json(model);
                }
            }
            catch (Exception ex)
            {
                errorMessage = ex.Message;
            }
            Response.StatusCode = 500;
            Response.StatusDescription = errorMessage;

            return Json(model);
        }

The jQuery Ajax Request

$.ajax({
            type: 'POST',
            data: { ServerName: serverName },
            url: getBaseURL() + 'Email_SmtpServer/_QueueCreate/',
            success: function (data) { onSuccess(data); },
            error: function (xhr, status, error) {
                $('#GeneralSMTPServerValidation').html(error);
            }
        });

Like I mentioned, yesterday, this was showing a nice message to the user informing them that the name they entered was not unique if it happened to exist. Now, all I’m getting is a “Internal Server Error” message…which is correct, as that’s what I am sending along in my when I set my Status Code. However, like I mentioned, it no longer sees the custom Status Description I send along.

I’ve also tried setting it to some unused status code to see if that was the problem, but that simply shows nothing because it doesn’t know what text to show.

Who knows? Maybe there’s something now wrong with my code. Most likely it was a change made somewhere else, what that could be, I have no idea. Does anyone have any ideas on what could be going wrong?

If you need any more code, I’ll try to provide it.

Thanks!

  • 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-27T14:11:26+00:00Added an answer on May 27, 2026 at 2:11 pm

    In your error callback, try using

    xhr.statusText
    

    Also, if you’re using Visual Studio’s webserver, you may not get the status text back.
    http://forums.asp.net/post/4180034.aspx

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

Sidebar

Related Questions

I am new to programming in general so please keep that in mind when
Please keep in mind that I am new to world of .Net and F#.
Please keep in mind that I'm new to C# and OOP so I apologize
Please keep in mind that I know nothing about Matlab. Matlab Builder JA lets
Please keep in mind that I'm a really newbie Cocoa developer Scenario: I've a
I have the following strange problem in Oracle (Please keep in mind that I
To keep things simple, please allow the assumption that some code requires the use
Please bear with me, I'm just learning C++. I'm trying to write my header
I have a new challenge today. I will develop a script that will take
What I want to do may seem like a weird scenario. Please keep in

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.