困扰了很久的问题,终于解决了,解决方案连接:

http://stackoverflow.com/questions/13292173/asp-net-mvc-razor-uploading-file-httppostedfilebase-always-null

 

 

@using(Html.BeginForm("Import","Home",FormMethod.Post,new{ enctype ="multipart/form-data"})){<input type="file" name="uploadFile"/><input type="submit" value="Importa"/>}

  

[AcceptVerbs(HttpVerbs.Post)] // or [HttpPost], nothing changes
public ActionResult Import(HttpPostedFileBase uploadFile)
{
   Debug.WriteLine("Inside Import");
   if (uploadFile == null)
       Debug.WriteLine("null");
   // Verify that the user selected a file
   if (uploadFile != null && uploadFile.ContentLength > 0)
   {
      Debug.WriteLine("Valid File");
      ...
   }
}

  


需要在View中添加
@data_ajax="false"



呼,舒服~

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-16
  • 2021-12-16
  • 2021-04-22
  • 2021-05-15
猜你喜欢
  • 2021-07-29
  • 2022-12-23
  • 2021-12-25
  • 2021-10-05
  • 2021-12-18
  • 2022-12-23
  • 2021-07-23
相关资源
相似解决方案