【发布时间】:2011-11-08 10:02:59
【问题描述】:
我是 MVC3 的初学者,还在学习。我尝试编写一个应用程序(带有 Razor 的 MVC3),它允许用户选择文件并上传/保存。在上传/保存过程中,我只想将“等待”文本显示为部分视图。我遇到了问题,因为 Web 应用程序一启动就加载了部分视图,并且 HomeController - [HTtpPost] Wait 方法出错,因为它无法跟踪对象作业中的列表文件。当然,文件列表将在上传后填写。我不知道如何解决这个问题,需要你的帮助。提前谢谢你。
我的 HomeController.cs :
public ActionResult Index()
{
return View();
}
[HttpPost]
public ActionResult UploadFile(IEnumerable<HttpPostedFileBase> attachments)
{
foreach ( var file in attachments )
{
// do something
}
return RedirectToAction("Wait");
}
public ActionResult Wait()
{
// do something
ViewBag.Message = "Wait...";
return View();
}
[HttpPost]
public ActionResult Wait(FormCollection formCollection)
{
Work job = MvcApplication.GetWork();
if ( job.Files.Any() )
{
return RedirectToAction("SubmitWork");
}
else
{
return View();
}
}
视图Index.cshtml:
@{
ViewBag.Title = "FirstTry";
}
<p>
<div id="AddFiles">
@Html.Partial("_AddFiles")
</div>
</p>
<div id ="Wait">
@Html.Partial("_Wait")
</div>
部分视图_Wait.cshtml:
@{
ViewBag.Title = "Wait...";
}
@ViewBag.Message
@using ( Html.BeginForm("Wait", "Home", FormMethod.Post, new
{
id = "waitform"
}) )
{
}
<script type="text/javascript">
window.setTimeout("document.getElementById('waitform').submit()", 1000);
</script>
部分视图_AddFiles.cshtml:
@using ( Html.BeginForm("UploadFile", "Home", FormMethod.Post, new{id = "uploadForm", enctype = "multipart/form-data"}) )
{
@(Html.Telerik().Upload().Name("attachments").Multiple(true)
.Async(async => async.AutoUpload(true) )
)
<input type="submit" value="Send" class="t-button" />
<input type="reset" value="Reset" class="t-button" />
}
【问题讨论】:
标签: asp.net-mvc-3 razor partial-views