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

  • Home
  • SEARCH
  • 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 8230841
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T17:16:03+00:00 2026-06-07T17:16:03+00:00

I have a method I am calling via AJAX form my MVC3 application. The

  • 0

I have a method I am calling via AJAX form my MVC3 application. The method creates an image using the WebImage helper. After the image is created, I then return a Json result from the controller. What is actually returned looks like image data. The content type I am sendingin the headers for the request is json, so I am not sure why the server is return the image data rather than my actual json result. If I remove the WebImage code, I get the actual json result I am looking for.

Method example:

[HttpPost]
public ActionResult CreateTempImage(AvatarUploadModel avatar){

try{

var imageId = Guid.NewGuid();
            var newFileName = imageId + "_" + Path.GetFileName(avatar.FileName);
            var imageTempPath = Server.MapPath("~/Areas/Admin/TemporaryUploads/" + newFileName);
            var image = new WebImage(avatar.FileName).Resize(400, 400, true).Write();
            image.Save(imageTempPath);
return Json(new { success = true }, JsonRequestBehavior.AllowGet);
}
catch(Exception ex){
              return Json(new { success = false}, JsonRequestBehavior.AllowGet);
                   }
}

enter image description here

  • 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-07T17:16:06+00:00Added an answer on June 7, 2026 at 5:16 pm

    This code is your problem

    var image = new WebImage(avatar.FileName).Resize(400, 400, true).Write();
    

    It’s documented as…

    /// <summary>
    /// Renders an image to the browser.
    /// </summary>
    /// 
    /// <returns>
    /// The image.
    /// </returns>
    /// <param name="requestedFormat">(Optional) The file format to use when the image is written.    </param>
    

    Decompiling it gives the following code:

      requestedFormat = requestedFormat ?? this._initialFormat.ToString();
      byte[] bytes = this.GetBytes(requestedFormat);
      string str = !requestedFormat.StartsWith("image/", StringComparison.OrdinalIgnoreCase) ? "image/" + requestedFormat : requestedFormat;
      HttpResponse response = HttpContext.Current.Response;
      response.ContentType = str;
      response.BinaryWrite(bytes);
      return this;
    

    i.e. it’s writing the image directly to HttpContext.Current.Response and setting the ContentType to the image’s format.

    If you just want to save the image to the file system on the server then you can remove the call to Write and replace it with the call to Save:

    var image = new WebImage(avatar.FileName).Resize(400, 400, true).Save(imageTempPath);
    

    Cheers,
    Dean

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

Sidebar

Related Questions

I have a plugin for uploading files using jquery uploadify. After calling a method
It looks like #temptables created using dynamic SQL via the EXECUTE string method have
When using calling the SqlCommand.ExecuteReader() method, ReSharper tells me I have a possible NullReference
Edit: an important piece might be that I'm calling a cfc method via ajax...
I have a function calling a controller method in MVC3. $.getJSON('@Url.Action(LoadCitiesByProvince, Property)', { id:
I have two stateless SessionBeans. My client (JSF2 application) is calling a method (saveOrderCompletion)
I have the following code (calling a method returning IEnumerable): FibonacciWithLinq.Skip(delegate() { return 5;
I have a controller method that returns a jSON object and in one calling
I have a GridView which I am populating by calling a method to return
I know that I should have schema of a table before calling NewRow method

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.