I have a code for image upload . I used AjaxUpload.js plugin for uploading images without postback
. The problem is when i am passing hardcoded values (whether as query paramter or by data
helper) , I am able to retrieve that in my handler . But when i am passing some generic value like $('#some_id').val()
, then i always recieve empty string in my handler .
SCRIPT
var upload='';
upload = new AjaxUpload($('#fileOpenDialog'),
{
action: RootPath + 'GraphicResourceHandlers/FileHandler.ashx',
data: { OldGraphicName: $('#hidGraphicName').val() },
type: 'POST',
contentType: "application/json; charset=utf-8",
dataType: 'json',
autoSubmit: false,
onChange: function (file, extension) {
//some code
},
onSubmit: function (file, response) {
alert("Success.");
},
onError: function () {
alert("Error in upload.");
},
onComplete: function (file, response) {
//some code
}
});
//upload image
$('#btnUpload').click(function () {
//This will call the AjaxUpload .
upload.submit();
//Hides the modal that asks for uploading image
$('#browseFile').modal('hide');
});
FileHandler.ashx
public void ProcessRequest(HttpContext context)
{
try
{
context.Response.ContentType = " text/html";
//This line is returning an empty string
context.Request["OldGraphicName"]
//I also did this while passing as a query paramter but no luck
context.Request.QueryString["OldGraphicName"]
string graphicPath = Config.GraphicsPath;
string locationPath = HttpContext.Current.Request.PhysicalApplicationPath + graphicPath;
string fileName = context.Request.Files[0].FileName;
string newFileName = Guid.NewGuid() + Path.GetExtension(fileName);
context.Request.Files[0].SaveAs(locationPath + newFileName);
context.Response.Write(newFileName);
}
}
Can someone please look into this issue . I really toiled hard to figure out what is wrong on my part .
Thanks !