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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T06:33:34+00:00 2026-06-15T06:33:34+00:00

I am generating a small Json file which i wan’t the user to download.

  • 0

I am generating a small Json file which i wan’t the user to download. So i want the browser to prompt the user to download the file.

I’ve tried many of answers suggested in related questions but those won’t work for me.

The request is made by a click on an actionlink:

@Ajax.ActionLink("Generate JSON", "GenerateOcJson", new AjaxOptions { HttpMethod = "POST" })

i’ve tried:

var cd = new System.Net.Mime.ContentDisposition { FileName = fileName, Inline = false };
Response.AppendHeader("Content-Disposition", cd.ToString());

return File(Encoding.UTF8.GetBytes(jsonString),
            "application/json",
            string.Format(fileName));

and:

Response.Clear();
Response.ContentType = "application/json";
Response.AppendHeader("Content-Disposition", "attachment; filename=foo.json");
Response.Write(jsonString);
Response.End();

But the browser won’t download the file. I’m using MVC3 and this method is called by an actionlink. I’ve tried POST and GET requests.

If I inspect the request with Chrome i see the correct json had been written to the browser response.

Any clues? Thnx in advance

  • 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-15T06:33:35+00:00Added an answer on June 15, 2026 at 6:33 am

    Just return a file result with the Application/Octet mediatype. No need to write the content-disposition header.

    return File(Encoding.UTF8.GetBytes(jsonString),
                System.Net.Mime.MediaTypeNames.Application.Octet, 
                fileName);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im generating a file to present to the user for download, but the server
I have small script in bash, which is generating graphs via gnuplot. Everything works
I am generating new xml file using perl script but I have small problem,
I have a small Qt4 project which I want to build with cmake. It
I need to design a small project for generating excel reports in .NET, which
I'm looking for a .NET 2 library for generating charts. .NET 2 small footprint
Generating normal columnar data in excel file is quite easy but does any one
I have a large XML file (converted to JSON) that consists of multiple repeating
I've ran into one small problem. I am dynamically generating some controls and place
I'm trying to generate a small part of the page using jquery which is

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.