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

[Solved] OnRemove e.data parameters always null

5 Answers 243 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.
Sean
Top achievements
Rank 1
Sean asked on 04 Sep 2011, 06:47 AM
I'm using the onUpload and onRemove client events and attaching metadata per the documentation. It works great for onUpload, but when I set e.data for OnRemove, the values always come through as null. I even hardcoded one of the values for a parameter just to double-check that my variable shouldn't really be null. Am I doing something wrong?

        @(Html.Telerik().Upload()
            .Name("attachments")
            .Multiple(true)
            .Async(async => async
                .Save("SaveAttachment", "ControllerNameHere")
                .Remove("RemoveAttachment", "ControllerNameHere")
                .AutoUpload(true)
            )
            .ClientEvents(events => {
                events.OnRemove("onRemove");
                events.OnUpload("onUpload");
            })
        )

The javascript looks like this:

 

function onRemove(e) {

     e.data = { test: 1, imageIdentifier: $("#ImageIdentifier").val() };

    return true;

}

The controller method looks like this:

public ActionResult RemoveAttachment(string[] fileNames, int? test, Guid? imageIdentifier) {
    //test is null (hard-coded in the javascript just to prove it wasn't really null)
    //imageIdentifier is null

}

5 Answers, 1 is accepted

Sort by
0
T. Tsonev
Telerik team
answered on 07 Sep 2011, 12:07 PM
Hello Sean,

That's a known issue that we've managed to fix recently. The fix will be available in the SP1 release which is scheduled for September 15th.

Apologies for the caused inconvenience!

Greetings,
Tsvetomir Tsonev
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

0
Ravi
Top achievements
Rank 1
answered on 04 Apr 2012, 04:01 PM
Hello,

We are using 2012.1.214 version and i am having the same problem with upload button. Like i am trying to upload which multiple is false and for the second upload it is calling Remove server method with params null. I want to send the filename to that method but i can't.

My code snippet is:

@(Html.Telerik().Upload()
                               .Name("attachments")
                               .Multiple(false)
                               .Async(async => async
                               .Save("SaveTempFile", "FileUpload")
                                .Remove("Remove", "FileUpload")
                               .AutoUpload(true))
                               .ClientEvents(events => events
                                       .OnLoad("OnLoad")
                                       .OnSuccess("OnSuccess")
                                       .OnRemove("OnRemove")
           ))

public JsonResult Remove(string fileName)
{
}

Client event OnRemove is calling when i click on Remove not for second upload. so how to pass fileName  param to server method. 
0
T. Tsonev
Telerik team
answered on 05 Apr 2012, 02:40 PM
Hello,

We are not aware of such issue.

You can try the browser development tools or Fiddler to inspect the requests. You should be able to see if the file name is being sent to the server.

Regards,
Tsvetomir Tsonev
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now.
0
Douglas
Top achievements
Rank 1
answered on 04 May 2012, 08:07 PM
did you ever figure this out?

I am having the same problem:

http://www.telerik.com/community/forums/aspnet-mvc/upload/upload-remove-not-working.aspx 

The parameter mainImage is always null:

public ActionResult Remove(string mainImage)
    {
        var fileName = Path.GetFileName(mainImage);
        var physicalPath = Path.Combine(Server.MapPath("~/Flyers"), fileName);
 
        if(System.IO.File.Exists(physicalPath))
            System.IO.File.Delete(physicalPath);
        return Content("");
         
    }
0
Douglas
Top achievements
Rank 1
answered on 04 May 2012, 08:26 PM
Nevermind...

I opened up Google's developer tools to look at what was being posted back on REMOVE and noticed that I failed to adhere to the implementation to which Telerik had in their code:

public ActionResult Remove(string[] fileNames)
       {
           // The parameter of the Remove action must be called "fileNames"
           foreach (var fullName in fileNames)
           {
               var fileName = Path.GetFileName(fullName);
               var physicalPath = Path.Combine(Server.MapPath("~/App_Data"), fileName);
                
               // TODO: Verify user permissions
               if (System.IO.File.Exists(physicalPath))
               {
                   // The files are not actually removed in this demo
                   // System.IO.File.Delete(physicalPath);
               }
           }
           // Return an empty string to signify success
           return Content("");
       }


When I changed the parameter to a string array, it worked like a charm..

Tags
Upload
Asked by
Sean
Top achievements
Rank 1
Answers by
T. Tsonev
Telerik team
Ravi
Top achievements
Rank 1
Douglas
Top achievements
Rank 1
Share this question
or