2009-10-22 57 views
6

嘿家伙,我已得到uploadify处理一些文件上传在我的mvc项目和该部分工作非常好,我只是想知道我需要添加到我的控制器操作来获得访问该我从uploadify的javascript传递如何从uploadify在asp.net MVC控制器访问scriptDataData

编辑一些澄清scriptData变量:

我uploadify脚本如下:

var fileCategoryID; 
$(document).ready(function() { 
$('#uploadify').uploadify({ 
    'uploader': '../../scripts/uploadify.swf', 
    'cancelImg': '../../content/images/cancel.png', 
    'script': '../../' + $('#Controller').val() + '/FileSave/' + $('#OrderID').val(), 
    'folder': 'Uploads', 
    'multi': true, 
    'auto': false, 
    'queueSizeLimit': 5, 
    'queueID': 'fileQueue', 
    'displayData': 'speed', 
    'fileExt': '*.pdf', 
    'fileDesc': 'PDF', 
    'sizeLimit': '5242880', 
    'scriptData': { 'categoryID': fileCategoryID } 
}); 
$('#fileCategory').change(function() { 
    fileCategoryID = $('#fileCategory').val(); 
}); 
}); 

我很好奇我怎么可以从我的内部访问这些数据控制器动作

回答

4

通过接受我的控制器操作中的表单集合,我可以通过uploadify脚本访问categoryID参数,找到一个自己解决的答案。

编辑一些代码:

[AcceptVerbs(HttpVerbs.Post)] 
public string FileSave(long id, HttpPostedFileBase FileData, FormCollection forms) 
{ 
    long catID = Int64.Parse(forms.Get("CategoryID")); 

    //do something with files 

    return "Upload Successful"; 
} 
+0

您也可以使用formData选项 - 'formData':{'someKey':'someValu e','someOtherKey':1} – rboarman 2012-06-27 00:32:06

0
<script type="text/javascript"> 
    $(function() { 
     $('#file_upload').uploadify({ 
      'swf': "@Url.Content("~/Content/UploadifyContent/uploadify.swf")", 
      'cancelImg': "@Url.Content("~/Content/UploadifyContent/uploadify-cancel.png")", 
      'uploader': "@Url.Action("Upload", "Callout", new { @id = 5 })", 
      'scriptData': { 'id': $('#Job_Id').val() }, 
      'onUploadSuccess': function (file, data, response) { 
       $("#uploaded").append("<img src='" + data + "' alt='Uploaded Image' />"); 
      } 
     }); 
    }); 
</script> 

公众的ActionResult上传(长ID,HttpPostedFileBase的FileData) {

}

与$替换 '5'('#/ .blah')。val()或equiv

+0

感谢您的回答。不过,我认为嵌套引号字符存在一些问题。考虑编辑你的答案? – Barett 2014-07-22 23:47:16