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);
}
}

This code is your problem
It’s documented as…
Decompiling it gives the following code:
i.e. it’s writing the image directly to
HttpContext.Current.Responseand setting theContentTypeto 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
Writeand replace it with the call toSave:Cheers,
Dean