0

我有一个图片上传代码。我将AjaxUpload.js插件用于uploading images without postback. 问题是当我传递硬编码值(无论是作为查询参数还是通过data帮助程序)时,我能够在我的处理程序中检索它。但是当我传递一些通用值时$('#some_id').val(),我总是在我的处理程序中收到空字符串。

脚本

  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');
     });

文件处理程序.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);

        }
    }

有人可以看看这个问题。我真的很努力地找出我的问题所在。

谢谢 !

4

1 回答 1

0

你试过这个吗。。

var fileOpenDialog= $("#fileOpenDialog").val(); 

并在 ajax

data: {OldGraphicName: fileOpenDialog}

对不起,如果我错了....

于 2015-01-22T11:40:23.130 回答