简体   繁体   中英

How to pass more parameter to ashx asp.net?

About this, i founded more time , but seem it's not working. I have 2 textbox and 1 file input, and i want to upload some info and file(image). This is my code snippet. First in file .ashx

public void ProcessRequest(HttpContext context)
{
string text1 = context.Request["text1_temp"];
string number = context.Request["number_temp"];
HttpFileCollection files = context.Request.Files;
/////something 
}

And .aspx file

var files = $("#inputfile").get(0).files;
var test = new FormData();
///// only 1 file image
for (var i = 0; i < files.length; i++) {
test.append(files[i].name, files[i]);
}
///// add more parameter
test.append($("#txt_text1").val(), "text1_temp");
test.append($("#txt_number").val(), "number_temp");

if(!isImage($("#inputfile").val())){
alert("Not file Image");
return false;
}
else{
$.ajax({
url: "UploadPaper.ashx",
type: "POST",
contentType: false,
processData: false,
data: test,
success: function (result) {
console.log(result);
},
error: function (err) {
console.log(err.statusText);
}
});
return true;
}

Ok, look seem work, but when i run and debug at string text1 = context.Request["text1_temp"];string number = context.Request["number_temp"]; data text1 and number is null . Can you tell me what problem or mistake in here ? and how to fix it ? Thank you so much.

Because you are sending one object, not different parameters.

Instead you may use:

data: "{text1_temp: 'myValue',number_temp: '0'}",

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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