0
我正在使用mvc api和控制檯應用程序,並將其作爲服務使用。將文件從控制檯發送到mvc
MVC的代碼如下所示:
[HttpPost]
public ActionResult Index(HttpPostedFileBase file)
{
if (file.ContentLength > 0)
{
var fileName = System.IO.Path.GetFileName(file.FileName);
var path = System.IO.Path.Combine(Server.MapPath("~/App_Data/uploads"), fileName);
file.SaveAs(path);
}
return RedirectToAction("Index");
}
我嘗試不同的方法,我不能讓在MVC側無非file == null
多,任何幫助嗎?
你能描述一下如何從控制檯應用程序發出請求(甚至可能顯示代碼)嗎? – GolfWolf 2012-01-06 13:52:51
是Request.Files填充? – Pbirkoff 2012-01-06 14:00:14
您是否檢查過該文件實際上是否正在傳入該方法?而且它的長度實際上大於0?編輯: 這[從菲爾哈克博客文章](http://haacked.com/archive/2010/07/16/uploading-files-with-aspnetmvc.aspx)似乎回答你的問題。 – crunchy 2012-01-06 13:53:25