We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to pass additional data to save handler in UploadBox?

Platform: ASP.NET MVC |
Control: Uploadbox |
Published Date: June 12, 2015 |
Last Revised Date: May 8, 2019

Description

You can pass the data to the controller by using the Begin event of the UploadBox control. In the Begin event, pass the data in the script section.

 

Solution

You have to render the UploadBox control in the View page as shown in the following code example.

View

@Html.EJ().Uploadbox("UploadDefault").SaveUrl("SaveDefault").RemoveUrl("RemoveDefault").AllowDragAndDrop(true).MultipleFilesSelection(true).AsyncUpload(true).ClientSideEvents(e => e.Begin("onbegin")).ShowBrowseButton(false)

 

In the Begin event, pass the data in the script section as follows.

Script

function onbegin(args)

{

     args.data = "Uploadname";

}

 

After passing the data in the Begin event, pass the value as string in the controller page and return the data as shown in the following code example. Then, set the string value as the ID of the UploadBox continued by _data. For example, UploadDefault_data. Here, the ID of the UploadBox is UploadDefault.

Controller

public ActionResult SaveDefault(IEnumerable<HttpPostedFileBase> UploadDefault, string UploadDefault_data)
{
     foreach (var file in UploadDefault)
     {
          var fileName = Path.GetFileName(file.FileName);
          var destinationPath = Path.Combine(Server.MapPath("~/App_Data"), fileName);
          file.SaveAs(destinationPath);
      }
           ViewData["data"] = UploadDefault_data;
           return Content(UploadDefault_data);
}

 

 

Note:

Here, the UploadDefault_data is returned to the View page in order to display the additional data in the View page.

 

Sample Link:

http://www.syncfusion.com/uploads/user/directTrac/138287/UploadDragDrop-1596674697.zip

2X faster development

The ultimate ASP.NET MVC UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon