问题
I am trying to send parameters from my .aspx page into my handler.ashx with the help of "formdata" in uploadify using .net and c# when I upload a file. The parameters are take from textboxes that have values in the. The code is:
<script type = "text/javascript">
$(document).ready(function() {
$("#<%=FileUpload1.ClientID %>").uploadify({
'swf': 'Scripts/uploadify.swf',
'uploader': 'Handler.ashx',
'auto': true,
'multi': true,
'buttonText': 'Select File(s)',
'removeCompleted' : false,
'fileTypeDesc' : 'PDF Files',
'fileTypeExts' : '*.pdf',
'formData' : { "id": "<%=TBcustnom.Text %>", "pwd": "<%=Pwd.Text %>" }
});
});
handler.ashx only receives the first value (id), but not whats in the pwd part.
string id = context.Request["id"];
string pwd = context.Request["pwd"];
How do I configure the javascript to send both parameters? or how do I configure the handler.ashx to receive the pwd as well?
Best regards
回答1:
var data = {};
data.id = <%TBcustnom.Text %>;
data.pwd = <%Pwd.Text %>;
$(document).ready(function () {
$("#<%=FileUpload1.ClientID %>").uploadify({
'swf': 'Scripts/uploadify.swf',
'uploader': 'Handler.ashx',
'auto': true,
'multi': true,
'buttonText': 'Select File(s)',
'removeCompleted': false,
'fileTypeDesc': 'PDF Files',
'fileTypeExts': '*.pdf',
'formData': obj: JSON.stringify(data)
});
});
In the server side,
var jsonString = context.Request["obj"];
var serializer = new JavaScriptSerializer();
var jsonObjects = serializer.Deserialize<Dictionary<string, string>>(jsonString);
回答2:
The only thing I needed to do was to look at the right place.
string id = context.Request["id"];
string pwd = context.Request["pwd"];
this is supposed to be
string id = context.Request.Form[1];
string pwd = context.Request.Form[2];
Take care!
来源:https://stackoverflow.com/questions/17043672/uploadify-pass-formdata-variable-to-handler-ashx