ユーザーがファイルを送信できる部分ビューがあります。
<form action="Attachments" method="post" enctype="multipart/form-data" target="_self">
<div>
<label style="text-align: left;">Add File:</label>
</div>
<div>
<input type="file" name="file" id="file" style="width: 275px;" />
</div>
<div style="text-align: right;">
<input type="submit" value="Add"/>
</div>
</form>
これは、HTTPPost の AttachmentsController メソッドを呼び出します。
[HttpPost]
public ActionResult Index(HttpPostedFileBase file)
{
if (file.ContentLength > 0)
{
var fileName = Path.GetFileName(file.FileName);
var path = Path.Combine("C:\\Attachments", fileName);
file.SaveAs(path);
return AddAttachment(fileName);
}
return RedirectToAction("Failed", "Attachments");
}
addAttachment は「return RedirectToAction("Index", "Attachments");」を返します。添付ファイルを追加するためにこれがすべて完了した後、画面全体が更新され、添付ファイルを追加するための部分的なビューのみが更新されます。どうすればこれを達成できますか!?