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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T23:33:23+00:00 2026-06-05T23:33:23+00:00

I’m returning some Json via a C# MVC Controller. Other browsers work fine, but

  • 0

I’m returning some Json via a C# MVC Controller. Other browsers work fine, but Internet Explorer (IE9) tries to Save the returned Json data as a Text file. Any ideas how to keep this from happening?

//MVC Controller Code...
return Json(new { redirectToUrl = Url.Action("Create", "Album",
                  new { url = url, isLocalFile = isLocalFile})});

//Clientside Javascript Code
$("#uploadImageForm").ajaxForm({
  beforeSubmit: function () {

  },
  success: function (data, textStatus, xhr) {
          window.location.href = data.redirectToUrl;
  },
  error: function (data, textStatus, xhr) {
  } 
});

I’ve tried adding “text/plain” and “text/json” to the second argument of the return Json method, it doesn’t work.

Many 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-06-05T23:33:24+00:00Added an answer on June 5, 2026 at 11:33 pm

    Quote from the documentation of the jquery.form plugin:

    Browsers that support the XMLHttpRequest Level 2 will be able to
    upload files seamlessly and even get progress updates as the upload
    proceeds. For older browsers, a fallback technology is used which
    involves iframes since it is not possible to upload files using the
    level 1 implmenentation of the XMLHttpRequest object. This is a common
    fallback technique, but it has inherent limitations. The iframe
    element is used as the target of the form’s submit operation which
    means that the server response is written to the iframe. This is fine
    if the response type is HTML or XML, but doesn’t work as well if the
    response type is script or JSON, both of which often contain
    characters that need to be repesented using entity references when
    found in HTML markup.

    To account for the challenges of script and JSON responses when using
    the iframe mode, the Form Plugin allows these responses to be embedded
    in a textarea element and it is recommended that you do so for these
    response types when used in conjuction with file uploads and older
    browsers. Please note, however, that if there is no file input in the
    form then the request uses normal XHR to submit the form (not an
    iframe). This puts the burden on your server code to know when to use
    a textarea and when not to.

    This means that if your form contains file input fields and you are submitting this form to a controller action that returns JSON, you must wrap this JSON in a <textarea> tags.

    So your response should not look like this:

    { "redirectToUrl":"some url" }
    

    it should look like this:

    <textarea>{ "redirectToUrl":"some url" }</textarea>
    

    In order to achieve that you could use a custom action result that will wrap the response with those tags:

    public class TextareaJsonResult : JsonResult
    {
        public TextareaJsonResult(object data)
        {
            this.Data = data;
        }
    
        public override void ExecuteResult(ControllerContext context)
        {
            var response = context.HttpContext.Response;
            bool shouldWrap = !context.HttpContext.Request.IsAjaxRequest();
            if (shouldWrap)
            {
                response.Write("<textarea>");
            }
    
            base.ExecuteResult(context);
    
            if (shouldWrap)
            {
                response.ContentType = "text/html";
                response.Write("</textarea>");
            }
        }
    }
    

    and then have your controller action return this custom result:

    [HttpPost]
    public ActionResult Upload(HttpPostedFileBase file)
    {
        // ... some processing
    
        var redirectToUrl = Url.Action(
            "Create", 
            "Album",
            new { url = url, isLocalFile = isLocalFile }
        );
        return new TextareaJsonResult(new { redirectToUrl = redirectToUrl });
    }
    

    Now obviously in your AJAX success callback you also need to account for this difference by testing the typeof result and in the case of a legacy browser (such as Internet Explorer) manually parse the response. You may take a look at the source code of the page I have linked to.

    But this being said, I can see that in your success callback you are redirecting to a controller action contained in the JSON response returned by the server. Here comes my question: What’s the point of using AJAX in the first place if you are going to redirect? Why don’t you use a standard form post to the controller action and have the controller action directly perform the redirect? AJAX should be used when you want to stay on the same page.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;

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.