I have tried to find a good example with HTML/JavaScript/C# code to provide instruction on uploading only one file to the server for saving it to a directory on the server. My code gives me my variable, 'file', as null when I debug it.
HTML form:
<form id="uploadForm" method="post" data-dojo-type="dijit/form/Form" enctype="multipart/form-data">
<input
id="fileUploadInput"
type="file"
name="fileUploadInput"
>
<br />
<br />
<button
id="fileUploadButton"
data-dojo-attach-point="fileUploadButton"
onClick="click"
>
Upload
</button>
</form>
Dojo/JavaScript code:
ioIframe.send({
url: this.proxyPostFile,
form: "uploadForm",
method: "POST",
handleAs: "text",
// Callback on successful data call:
load: function (response, ioArgs) {
return response;
},
// Callback on errors
error: function (response, ioArgs) {
console.info(response)
}
});
c# code:
[HttpPost]
public JsonResult Upload(HttpPostedFileBase file)
{
JsonResult FileData = null;
if (Request != null)
{
try
{
if (file!=null && file.ContentLength > 0)
{
... do some stuff with the file
}
}
catch (Exception ex)
{
Dictionary<string,string> error = new Dictionary<string,string>();
error.Add("error", "ERROR:" + ex.Message.ToString());
FileData = Json(error);
}
}
else
{
Dictionary<string,string> callResponse = new Dictionary<string,string>();
callResponse.Add("filename", "You have not specified a file.");
FileData = Json(callResponse);
}
return FileData;
}
Any thoughts or help would be appreciated.
Thank You