This is a migrated thread and some comments may be shown as answers.

Upload Error

1 Answer 53 Views
Upload
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Swapnadip
Top achievements
Rank 1
Swapnadip asked on 27 Apr 2012, 01:07 PM
Hi all,
   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?

1 Answer, 1 is accepted

Sort by
0
Pechka
Top achievements
Rank 1
answered on 30 Apr 2012, 08:15 AM
Hi,

http://www.telerik.com/help/aspnet-mvc/telerik-ui-components-upload-asynchronous-upload.html 

says 

// Return an empty string to signify success
    return Content("");

In your code you perform redirect - which is useless and is causing an error.

To change the button label use the OnLoad event and this handler:

function onLoad() {
  $(this).find('span').html('Test ...');
}

Tags
Upload
Asked by
Swapnadip
Top achievements
Rank 1
Answers by
Pechka
Top achievements
Rank 1
Share this question
or