我有這樣的控制器:如何將文件傳遞給控制器
public ActionResult Index(HttpPostedFileBase file)
{
if (file != null && file.ContentLength > 0)
try
{
string path = Path.Combine(Server.MapPath("~/Files"),
Path.GetFileName(file.FileName));
file.SaveAs(path);
ViewBag.Message = "Success";
}
catch (Exception ex)
{
ViewBag.Message = "Error:" + ex.Message.ToString();
}
return RedirectToAction("NewController", new { myFile : file });
}
我的新控制器:
public ActionResult NewController(HttpPostedFile myFile)
{
}
我想「文件」傳遞給NewController
但它給了我一個錯誤在RedirectToAction
。我如何將正確的值傳遞給RedirectToAction
以便它能正常工作?謝謝。
什麼是錯誤 –