我在局部视图中有一个文件上传控件(_Managefiles),
@model Framework.Views.FileUpload
...
@{
var grid = new WebGrid(Model.UploadFileList, ...);}
<div id="gridContent">
@grid.GetHtml(tableStyle: "webGrid",...)
@using (Html.BeginForm("UploadFiles", "PartialVw", FormMethod.Post,
new { enctype = "multipart/form-data", Id = "frmManageFiles", UpdateTargetId = "Grd" }))
{
..
<input id="uploadFile" name="uploadFile" type="file" />
<input type="button" id="btnSubmit" value="Upload File" onclick="javascript:StoreFormData()" />
}
此局部视图位于视图(Expense.cshtml)的弹出窗口中,
@model Framework.Views.Expenses
...
<div id="FileUploadModal" title="Upload File" style="display: none; overflow: auto;">
@Html.Partial("../Shared/_ManageFiles", Framework.Views.FileUpload.Current)
</div>
点击视图中的网格行项目链接,显示上传弹出窗口,上传文件上传点击按钮,下面是控制器事件
[HttpPost]
public ActionResult UploadFiles(FormCollection form)
{
HttpPostedFileBase File = Request.Files["uploadFile"];
...
File.SaveAs(FileUpload.Current.UploadFolderPath);
return View("../Expenses/Expenses", Expenses.Current);
}
每次上传后弹出窗口消失,下载后应该保持不变。我正在考虑使用ViewData,弹出窗口是否有任何解决方法可以保留?
我不想使用任何上传控件,如uploadify,blueimp。我想保持简单。
答案 0 :(得分:0)
我为上传控件创建了一个普通视图而不是部分视图,而是点击了网格行项链接,打开了一个新窗口,这样只会在上传时刷新新打开的窗口
function UploadExpenseFile(e) {
var l = (screen.width - 500) / 2;
var t = (screen.height - 500) / 2;
var f = window.open("@Url.Action("ManageFiles", "Tools", new { itemid = "_id" })".replace("_id",e), "_blank", 'resizable=0, height=500px,width=500px,top=' + t + ',left=' + l + 'w');
}