【问题标题】:Kendo MVC multiple uploadersKendo MVC 多个上传器
【发布时间】:2014-02-06 01:29:30
【问题描述】:

我正在使用带有 MVC 的剑道控件。我有一个基本的上传器工作,但我需要动态创建它们并在后端处理该代码。这是我正在工作的简单示例

<input name="attachments" type="file" id="attachments" />
<script type="text/javascript">
    $(document).ready(function () {
        $("#attachments").kendoUpload({
            async: {
                saveUrl: '@Url.Action("Save", "AppConfig")',
                autoUpload: true
            }
        });
});
</script>
[HttpPost]
    public ActionResult Save(IEnumerable<HttpPostedFileBase> attachments)
    {

        if (SaveUploadedFile(attachments, "Background"))
        {
            return Content("");
        }
        else
        {
            return Content("error");
        }

    }

但是,我需要做的是动态创建 ID 并在后端处理它。所以这就是我制作文件上传器的方式

@foreach (var item in Model) {
    string fid = String.Format("{0}{1}", @item.fieldType, @item.appConfigId.ToString());
                <input name="@fid" id="@fid" type="file" />
                <script type="text/javascript">
                    $(document).ready(function () {
                        $("#@fid").kendoUpload({
                        async: {
                            saveUrl: '@Url.Action("Save", "AppConfig")',
                            autoUpload: true
                        }
                    });
                });
                </script>

}

现在我知道 HttpPostedFileBase 参数必须与您的 html 元素的 id 匹配,但我不知道如何修改后面的代码,以便可以接收多个上传者。有什么想法吗?

【问题讨论】:

    标签: asp.net-mvc asp.net-mvc-4 kendo-ui


    【解决方案1】:

    为什么不直接使用上传器的 multiple 功能?默认开启。

    【讨论】:

    • 因为我目前的情况不允许这样做。每个文件上传都与某些特定的有关。我只是简化了我的代码正在做的事情,以供在这里阅读它的人使用。它所在的 for 循环要复杂得多。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多