私はMVC3で初心者で、まだ学習しています。私は、ユーザーがファイルを選択してアップロード/保存できるアプリケーション(Razor付きのMVC3)を作成しようとしています。アップロード/保存プロセス中に、単に「待機」テキストを部分表示として表示したい。 Webアプリケーションが起動するとすぐに部分ビューがロードされ、HomeController - [HTtpPost] Waitメソッドからエラーが発生したので問題があります。オブジェクトジョブのリストファイルをトレースできないためです。もちろん、ファイルのリストはアップロード後に埋められます。私はこれを解決する方法を知らず、あなたの助けが必要です。前もって感謝します。MVC3 Razor:部分ビューを条件付きで読み込む方法は?
マイ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:MVCはWebフォームのように動作しません
@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" />
}