简体   繁体   English

将参数从Jquery传递到webhandler asp.net C#

[英]Pass parameter from Jquery to webhandler asp.net c#

I want to be able to drag and drop files into multiple folders on a server, I am using jquery to pass to HttpHandler but I can't pass the save location to webhandler. 我希望能够将文件拖放到服务器上的多个文件夹中,我正在使用jquery传递给HttpHandler,但是无法将保存位置传递给webhandler。 I would like to send the path from jquery in the request is there a way to incluse that when the data for file transfer is passed. 我想在请求中从jquery发送路径,有没有一种方法可以包括在传递文件传输数据时。

         $.ajax({
            type: "POST",
            url: "FileHandler.ashx",
            contentType: false,
            processData: false,
            data: data,
            success: function (result) {
                alert(result);
            },
            error: function () {
                alert("There was error uploading files!");
            }
        });

Maybe something like this: 也许是这样的:

        $.ajax({
            type: "POST",
            url: "FileHandler.ashx",
            contentType: false,
            processData: false,
            data: data,
            filepath: document.getElementById("<%=listDrop.ClientID%>");
            success: function (result) {
                alert(result);
            },
            error: function () {
                alert("There was error uploading files!");
            }
        });

and then retrieve the path in the webhandler to pass as save location? 然后在webhandler中检索路径以作为保存位置传递?

I have tried this $.ajax({ type: "POST", url: "FileHandler.ashx", contentType:false, processData: false, data: { data: newData, filepath:JSON.stringify("~/uploads/") },
success: function (result) { alert('success'); }, error: function () { alert("There was error uploading files!"); } });
我已经尝试过$.ajax({ type: "POST", url: "FileHandler.ashx", contentType:false, processData: false, data: { data: newData, filepath:JSON.stringify("~/uploads/") },
success: function (result) { alert('success'); }, error: function () { alert("There was error uploading files!"); } });
$.ajax({ type: "POST", url: "FileHandler.ashx", contentType:false, processData: false, data: { data: newData, filepath:JSON.stringify("~/uploads/") },
success: function (result) { alert('success'); }, error: function () { alert("There was error uploading files!"); } });
But I have question about the declaration of the data type for the files I will be uploading when creating the get and set in asp. 但是我对在asp中创建get和set时要上传的文件的数据类型的声明有疑问。 filepath is a string but what data type are the files. filepath是一个字符串,但是文件是什么数据类型。

although i am answering from my mobile, i tried my best to keep the things intact and use ful. 尽管我通过手机应答,但我仍尽力使事情保持完整并使用有效。 If required, Please format it accordingly. 如果需要,请进行相应的格式化。 I am not going to write entire code here, just algo. 我不会在这里写整个代码,只是算法。 1. Identify the parameter to be passed. 1.确定要传递的参数。 If its only path of multiple folders then you can create an array of objects in javascript for the same. 如果它只是多个文件夹的唯一路径,则可以在javascript中为同一对象创建对象数组。 See tge example var listOfFolder = new string[]; 参见tge示例var listOfFolder = new string []; listOfFolder[0]="path of first dir"; listOfFolder [0] =“第一个目录的路径”; : : listOfFolder[n]="path of nth dir"; ::listOfFolder [n] =“第n个目录的路径”; var data = JSON.stringify(listOfFolder); var data = JSON.stringify(listOfFolder); 2. pass this data in data attribute of jquery ajax. 2.将此数据传递到jquery ajax的data属性中。 3. Grab this path in Process Request event and deserialize. 3.在“流程请求”事件中获取此路径并反序列化。 4. Do whatever you want. 4.做任何你想做的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM