gpt4 book ai didi

c# - HttpPostedFileBase 返回 null

转载 作者:太空宇宙 更新时间:2023-11-03 22:01:12 24 4
gpt4 key购买 nike

我正在尝试在 ASP.NET MVC 中上传单个 .csv 文件。在我的 .ascx 文件中,我有:

        <div>           
<input type="file" name="file" id="file" />
&nbsp &nbsp
<input type="submit" name="btnSubmit" id="btnSubmit" value="Upload" />
</div>

Controller Action 是:

 public ActionResult Upload(HttpPostedFileBase file)
{
if (file.ContentLength > 0)
{
var fileName = Path.GetFileName(file.FileName);
var path = Path.Combine(Server.MapPath("~/App_Data/uploads"), fileName);
file.SaveAs(path);
}
return View();
}

问题是我在上传操作中总是将文件设为 Null。关于如何让它工作有什么建议吗?

最佳答案

你确定你有一个

<form enctype="multipart/form-data" method="post">
<div> bla bla
</div>
</form>

?

编辑:方法=“发布”

+

[HttpPost]

关于你的行动

关于c# - HttpPostedFileBase 返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10032087/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com