This question is locked. New answers and comments are not allowed.
Hi,
I am using telerik upload control to upload a csv file.But when i am trying to upload a file it doesnot upload any files also is not going through my controller action.
Below is the code snippet i am using for my View and the controller.
Please let me know if i am missing anything.
View:
@(Html.Telerik().Upload()
.Name("Loans")
.Async(async => async
.Save("SaveFile", "LockLoans")
)
.ClientEvents(events => events.OnUpload("onUpload").OnSuccess("onSuccess").OnRemove("onRemove"))
)
Controller:
[HttpPost]
public ActionResult SaveFile(IEnumerable<HttpPostedFileBase> attachments)
{
req = new RequestService.Service1Client();
Byte[] fileData = null;
foreach (var file in attachments)
{
using (var binaryReader = new System.IO.BinaryReader(Request.Files[0].InputStream))
{
fileData = binaryReader.ReadBytes(Request.Files[0].ContentLength);
}
//save files into database
req.ExecuteAction(129, currentUserID, Carma.Library.Models.Environment.Source, "SaveFile",
new UploadFile
{
Contents = fileData,
FileName = file.FileName.Substring(file.FileName.LastIndexOf("\\") + 1),
DateTime = DateTime.Now.ToString()
}, null);
}
return Json(new { status = "OK" }, "text/plain");
}
I am using telerik upload control to upload a csv file.But when i am trying to upload a file it doesnot upload any files also is not going through my controller action.
Below is the code snippet i am using for my View and the controller.
Please let me know if i am missing anything.
View:
@(Html.Telerik().Upload()
.Name("Loans")
.Async(async => async
.Save("SaveFile", "LockLoans")
)
.ClientEvents(events => events.OnUpload("onUpload").OnSuccess("onSuccess").OnRemove("onRemove"))
)
Controller:
[HttpPost]
public ActionResult SaveFile(IEnumerable<HttpPostedFileBase> attachments)
{
req = new RequestService.Service1Client();
Byte[] fileData = null;
foreach (var file in attachments)
{
using (var binaryReader = new System.IO.BinaryReader(Request.Files[0].InputStream))
{
fileData = binaryReader.ReadBytes(Request.Files[0].ContentLength);
}
//save files into database
req.ExecuteAction(129, currentUserID, Carma.Library.Models.Environment.Source, "SaveFile",
new UploadFile
{
Contents = fileData,
FileName = file.FileName.Substring(file.FileName.LastIndexOf("\\") + 1),
DateTime = DateTime.Now.ToString()
}, null);
}
return Json(new { status = "OK" }, "text/plain");
}