[RESOLVED]Returning and processing JSON after an iframe file upload

I’m using the following iframe aysnchronous file upload trick:

<iframe id="import_target" name="import_target" style="display: none;"></iframe>

<form action="@Url.Action("ProcessImport")" method="post" enctype="multipart/form-data" target="import_target">
    <input type="file" name="file" />
    <input type="submit" value="Import" />

And here’s the ProcessImport C# method:

public ActionResult ProcessImport(HttpPostedFileBase file)
    string theUploadedFileIsAlreadyJson = new StreamReader(file.InputStream).ReadToEnd();
    return Json(theUploadedFileIsAlreadyJson);

For some reason, returning Json offers a download file dialog. Is there any way to output the Json to the iframe instead, so that it can be picked up and processed by Javascript?

Nevermind – using return Content() rather than return Json() is the correct way to approach this.

Leave a Reply