如何获取jQuery的Uploadify插件与ASP.NET MVC工作? [英] How do I get jQuery's Uploadify plugin to work with ASP.NET MVC?
问题描述
我在试图让jQuery插件, Uploadify ,与ASP.NET MVC的工作过程。
我有显示出来罚款与以下JavaScript插件片段:
<脚本类型=文/ JavaScript的>
$(文件)。就绪(函数(){
$('#文件上传')。文件上传({
'上传':'/Content/Flash/uploader.swf',
'脚本':'/定位/上传',
文件夹:'/上传',
'多':'真',
buttonText':'浏览',
displayData':'速度',
'simUploadLimit':2,
cancelImg':'/Content/Images/cancel.png
});
});
< / SCRIPT>
这似乎是一切都很好很好。如果您发现,脚本属性设置为我/展示/上传,这是我的配置控制器和我的上传操作。
主要的问题是,我有困难得到这个动作射击接收文件。我设置上行动断点,当我选择要上传的文件,是没有得到执行它。
我试着改变基于方法签名关本文:
公共字符串上传(HttpPostedFileBase的FileData)
{
/ *
*
*做一些与的FileData
*
* /
返回上传OK!;
}
但是,这仍然不火。
谁能帮我写,准确获得上传控制器操作的签名,以便它实际上火?然后,我可以处理文件数据处理自己。我只是需要一些帮助获取方法的动作射击。
公共字符串上传(HttpPostedFileBase的FileData){}
是正确的 - 由uploadify上传的文件将获得绑定到的FileData。无需进入Request.Files检索文件 - 这使得它难以模拟和测试
如果你的动作不点火在所有(即尝试调试,看看方法中的一个断点命中),那么你的问题是最有可能的脚本的价值 - 你的虚拟目录下运行?如果是这样,你需要在前面把目录的名称。 Uploadify使用绝对路径。
即。 脚本:'/ virtual_directory /布局/上传
现在uploadify发送到 HTTP://本地主机/定位/上传
也尝试使用route调试器(<一个href=\"http://haacked.com/archive/2008/03/13/url-routing-debugger.aspx\">http://haacked.com/archive/2008/03/13/url-routing-debugger.aspx)以检查您的路线被映射到。
I'm in the process of trying to get the jQuery plugin, Uploadify, to work with ASP.NET MVC.
I've got the plugin showing up fine with the following JavaScript snippet:
<script type="text/javascript">
$(document).ready(function() {
$('#fileUpload').fileUpload({
'uploader': '/Content/Flash/uploader.swf',
'script': '/Placement/Upload',
'folder': '/uploads',
'multi': 'true',
'buttonText': 'Browse',
'displayData': 'speed',
'simUploadLimit': 2,
'cancelImg': '/Content/Images/cancel.png'
});
});
</script>
Which seems like all is well in good. If you notice, the "script" attribute is set to my /Placement/Upload, which is my Placement Controller and my Upload Action.
The main problem is, I'm having difficulty getting this action to fire to receive the file. I've set a breakpoint on that action and when I select a file to upload, it isn't getting executed.
I've tried changing the method signature based off this article:
public string Upload(HttpPostedFileBase FileData)
{
/*
*
* Do something with the FileData
*
*/
return "Upload OK!";
}
But this still doesn't fire.
Can anyone help me write and get the Upload controller action's signature correctly so it will actually fire? I can then handle dealing with the file data myself. I just need some help getting the method action to fire.
public string Upload(HttpPostedFileBase FileData) {}
is correct - the file uploaded by uploadify will get binded to FileData. No need to get into Request.Files to retrieve the file - which makes it harder to mock and test.
If your action isn't firing at all (i.e. try debugging and see if a breakpoint within the method is hit), then your issue is most likely the 'script' value - are you running under a virtual directory? If so you'll need to put the name of the directory in front. Uploadify is using an absolute path.
i.e. 'script: '/virtual_directory/Placement/Upload'
right now uploadify is sending to http://localhost/Placement/Upload.
also try using the route debugger (http://haacked.com/archive/2008/03/13/url-routing-debugger.aspx) to check where your route is being mapped to.
这篇关于如何获取jQuery的Uploadify插件与ASP.NET MVC工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!