gpt4 book ai didi

c# - 上传的 HttpPostedFile 为空

转载 作者:IT王子 更新时间:2023-10-29 04:40:39 26 4
gpt4 key购买 nike

在 View 上:

<% =Html.BeginForm("About", "Home", FormMethod.Post, new {enctype="multipart/form-data "})%>
<input type="file" name="postedFile" />
<input type="submit" name="upload" value="Upload" />
<% Html.EndForm(); %>

在Controller中,有这样的东西:

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult About(HttpPostedFile postedFile)
{
//but postedFile is null
View();
}

postedFile 在 About() 中为空。如何上传文件?

最佳答案

使用 HttpPostedFileBase(不是 HttpPostedFile),并按照表单中的名称准确命名参数。例如。如果你有

<input type="file" id="file1" name="file1" />

你必须有方法头:

public ActionResult About(HttpPostedFileBase file1)

关于c# - 上传的 HttpPostedFile 为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/544182/

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