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.
Unfortunately, activation email could not send to your email. Please try again.

Post Upload Information

Thread ID:

Created:

Updated:

Platform:

Replies:

128357 Jan 16,2017 07:56 PM Nov 7,2017 01:06 AM ASP.NET MVC 5
loading
Tags: Uploadbox
Richard Dublon
Asked On January 16, 2017 07:56 PM

Hi, 
I am using an upload box in an MVC application and was wondering how to send back pass or fail information back to the view.  
I am using the upload box to load an Excel file into a dataset and eventually insert that data into a sql database.  All of that is working nicely when the data is correct in the Excel and If the data is not ok, it correctly shows a red X in the upload box to the user signifying that the upload failed.
I would also like to pass on more data to the user from the Controller(count of records inserted or failed, etc...) but I can't seem to update my view.  
I have tried to pass data to the viewbag but it looks like I need to use the return Content statement or else the upload box will show the red X even if it is successful.  
How can this be done?
Thanks

Gopi Govindasamy [Syncfusion]
Replied On January 17, 2017 06:54 AM

Hi  
 
We are sorry that we couldn’t understand the reported query clearly. Can you please provide more details on your requirement. It will help us to provide a solution.  
  
Please let us know if you need any other help.  
  
Regards,  
Gopi G. 


Richard Dublon
Replied On January 17, 2017 08:46 AM

Sorry for the confusion.
Basically I am trying to update my view with controller information after using the upload box.  Is a post or refresh happening or something else that is causing the viewbag not to be displayed?

Richard Dublon
Replied On January 18, 2017 11:40 AM

I have another question besides the one above.  How do I pass something back from within the return Content  statement that doesn't result in a red X when the import has completed.

I have the following:

                result = successCount + "_" + failedCount;

                return Content(result);

If I do the above, my upload box shows a red X as if the file failed even though it uploaded correctly.

Thanks

Richard Dublon
Replied On November 6, 2017 04:26 PM

All of this worked great...thank you.

I have another question.  Is there a way to pass data besides the file name to my controller?  For example, lets say I want to append some text to my file name in javascript in the file selected event as an identifier and I want to do something with that extra text in my controller in the same action result as my file upload...can this be done?



Keerthana Rajendran [Syncfusion]
Replied On November 7, 2017 01:06 AM

Hi Richard,   
  
Query: Is there a way to pass data besides the file name to my controller?  For example, lets say I want to append some text to my file name in javascript in the file selected event as an identifier and I want to do something with that extra text in my controller in the same action result as my file upload...can this be done?   
 
Response: Yes, you can pass additional data to controller through begin event of Uploadbox as shown below.   
     
@Html.EJ().Uploadbox("UploadDefault").SaveUrl("SaveDefault").RemoveUrl("RemoveDefault").ClientSideEvents(e=>e.FileSelect("onselect").Begin("uploadbegin"))   
    <script>   
        function onselect(args)   
        {   
            for (i = 0; i < args.files.length;i++)   
            {   
                args.files[i].name= args.files[i].name + "file" +i   
            }   
        }   
   
        function uploadbegin(args)   
        {   
              args.data= args.files.name    
        }   
    </script>   
 
Pass the data during begin event in script section and receive this string as additional parameter with Upload box id as shown below   
  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);   
         }   
 
We have attached a sample for reference. Please download the sample from:   
Please refer the below KB for more details:   
   
Regards,   
Keerthana.   
 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

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.

;