【发布时间】: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