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