I am using Telerik upload control to upload the files and I am trying to save the file name and the filepath into a database.. Here is my code..
View:
@(Html.Telerik().Upload()
.Name(
"files")
.Multiple(true)
.ShowFileList(false)
.Async(async => async
.Save("Save", "ClaimHoldRelease", new { id = ViewBag.EmpId})
.Remove("Remove", "ClaimHoldRelease")
.AutoUpload(true)
)
)
Controller:
[HttpPost]
public ActionResult Save(IEnumerable<HttpPostedFileBase> files, string id)
{
ViewData["EmpId"] = id;
foreach (var file in files)
{
ViewData["EmpId"] = id;
var fileName = id + Path.GetFileName(file.FileName);
var destinationPath = Path.Combine(Server.MapPath("~/App_Data/uploads"), fileName);
file.SaveAs(destinationPath);
Attachment attachment= new Attachment();
attachment.EmpID= id;
attachment.AttachmentPath = destinationPath;
attachment.FileName = fileName;
db.Attachments.Add(attachment);
db.SaveChanges();
}
return RedirectToAction("Index", new RouteValueDictionary(
new { controller = "Home", action = "Index", Id = id }));
}
Every time when iam trying to upload files it is showing aa alertBox with the message
Error! Upload failed. Unexpected server response - see console
But the data is saving correctly into the database.
How can I overcome this problem?
and How can I change the Button name SELECT?