Nic*_*ger 3 asp.net asp.net-mvc jquery dropzone.js
刚开始使用Dropzone,到目前为止它看起来非常好.我有后端功能来处理上传本身,但是在调试时我注意到动作永远不会被击中.这是因为我的表单包含一个隐藏的输入,用于传递所需的id(用于执行上载的操作).这是我的表格:
@using (Html.BeginForm("UploadFile", "UnitSummary", FormMethod.Post, new
{
enctype = "multipart/form-data",
id = "imgUpload",
@class = "dropzone"
}))
{
<div class="fallback">
<input name="file" type="file" multiple />
<input type="submit" value="Upload" />
<input type="hidden" name="unitId" value="@Model.ViewUnitContract.Id"/>
</div>
}
Run Code Online (Sandbox Code Playgroud)
JS:
<script type="text/javascript">
$(document).ready(function () {
// Dropzone
Dropzone.options.imgUpload = {
paramName: "file", // Must match the name of the HttpPostedFileBase argument that the Upload action expects.
acceptedFiles: "image/*" // Accept images only
};
});
</script>
Run Code Online (Sandbox Code Playgroud)
这是我的行动:
[HttpPost]
public ActionResult UploadFile(HttpPostedFileBase file, int unitId)
{
...
}
Run Code Online (Sandbox Code Playgroud)
现在,如果我删除"int unitId"参数,则会触发此操作.唯一的问题是我实际上需要那个id :)
使用以下形式解决:
<form action="/UnitSummary/UploadFile?unitId=@Model.ViewUnitContract.Id" class="dropzone" enctype="multipart/form-data" id="imgUpload" method="post">
<div class="fallback">
<input name="file" type="file" multiple />
<input type="submit" value="Upload" />
</div>
</form>
Run Code Online (Sandbox Code Playgroud)
控制器动作和js保持不变.
| 归档时间: |
|
| 查看次数: |
3303 次 |
| 最近记录: |