0

我有一个视图模型,它显示在使用uploadify 的视图中。我需要在帖子中传回收集数据。我怎样才能做到这一点?

视图模型:

public class ViewModel
{
   string Name;
   IEnumerable<Junk> theJunk;
}

public Junk
{
   int id;
   string Name;
}

看法:

@model ViewModel

@using (@Html.BeginForm())
{
  <input type="file" name="dr405" id="dr405" />

    <div>
        @Html.LabelFor(model => model.Name)
        @Html.EditorFor(model => model.Name)
    </div>        
    @Html.EditorFor(model => model.theJunk)

    <input type="submit" value="Upload Junk" /> 
}

<script type="text/javascript">
    jQuery.noConflict();
    jQuery(document).ready(function () {
        jQuery("#dr405").uploadify({
            'uploader': '@Url.Content("~/Scripts/uploadify.swf")',
            'cancelImg': '/Content/themes/base/images/cancel.png',
            'buttonText': 'Browse Files',
            'script': 'home/upload',
            'folder': '/uploads',
            'fileDesc': 'Image Files',
            'fileExt': '*.jpg;*.jpeg;*.gif;*.png',
            'sizeLimit': '38000',
            'multi': true,
            'auto': true,
        });
    }); 
    </script> 

控制器:

   [HttpPost]
    public ActionResult Upload(HttpPostedFileBase fileData, FormCollection collection)
    {
        // Get my view model here
        // ...get the main Name!
        // ...get the collection of Junk 

        return "ok";
    }
4

1 回答 1

3

这是一篇介绍这种情况的文章。您可以使用scriptData允许您将附加值传递给服务器的参数。但是由于uploadify为每个文件发送多个请求(假设您已将multi选项设置为true),您可以有2个控制器操作:第一个将针对每个选定的文件进行命中,以便将其保存在某处,第二个将是一次热所有文件都已上传并发送表单数据。auto如果您不希望在选择文件后立即开始上传,您还应该将该选项设置为 false。

于 2012-04-11T06:20:21.620 回答