Aug 12, 2014, 7:41 PM
Uploading file
Hi,
I want to use the button only method to attach a file to the FileUploadField. However, when I call the controller action, I get a null file.
The relevant code is as such:
I want to use the button only method to attach a file to the FileUploadField. However, when I call the controller action, I get a null file.
The relevant code is as such:
//Inside View
X.FileUploadField()
.Listeners(ld => ld.Change.Handler = "#{DirectMethods}.FileUpload()")
.ButtonOnly(true)
.ButtonText("Open..."),
//Controller Action
[DirectMethod]
public ActionResult FileUpload()
{
if (this.GetCmp<FileUploadField>("FileUploadField1").HasFile) //This section never runs
{
HttpPostedFile file = this.GetCmp<FileUploadField>("FileUploadField1").PostedFile;
var filename = Path.GetFileName(file.FileName);
var path = Path.Combine(Server.MapPath("~/Content/images"), filename);
file.SaveAs(path);
}
DirectResult result = new DirectResult();
result.IsUpload = true;
return result;
}
Any help is much appreciated.
Last edited by massman07; Aug 12, 2014 at 7:45 PM.