Implemented HTML code to receive a file and send it to the server. However, I prefer to keep the data on the client side instead of the server. How can I achieve this while still being able to access the data? The solution needs to be compatible with IE8 or at least IE9. On the client side, I'm using Javascript and KnockoutJS, while on the server side, C#/asp.net MVC is being utilized.
This is how the file is currently sent to the server. As it's a POST Method, I assume there should be a way to return something. Perhaps I am misunderstanding its usage.
@using (Html.BeginForm("loadReport", "home", FormMethod.Post, new {enctype="multipart/form-data"})){
<input type="file" name="FileUpload1" /><br />
<input type="submit" name="Submit" id="Submit" value="Upload" />}
public ActionResult loadReport()
{
foreach (string upload in Request.Files)
{
// if (!Request.Files[upload].HasFile()) continue;
string path = AppDomain.CurrentDomain.BaseDirectory;
string filename = Path.GetFileName(Request.Files[upload].FileName);
Request.Files[upload].SaveAs(Path.Combine(path, filename));
System.Diagnostics.Debug.WriteLine(Path.GetFileName(Request.Files[upload].FileName));
}
return this.Json(new { });
}
The above snippets are from a blog post that explains how to upload files to the server. Instead of returning JSON data, they returned a view. Testing this method led to a new page loading rather than receiving a JSON file for my Javascript.