MVC 在用到上传文件控件时,必须添加enctype = "multipart/form-data"属性,

Html.BeginForm("action","controller",FormMethod.Post,new{enctype = "multipart/form-data"})

{

   <input type="file" />

}

enctype = "multipart/form-data的作用是:设置表单的MIME编码。默认情况,这个编码格式是application/x-www-form-urlencoded,不能用于文件上传;只有使用了multipart/form-data,才能完整把数据提交到controller(后台代码)中。

相关文章:

  • 2021-11-28
  • 2022-01-10
  • 2022-12-23
  • 2022-12-23
  • 2021-09-15
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-11-14
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-10
  • 2022-12-23
相关资源
相似解决方案