我知道有很多这样的问题,但我阅读了所有这些问题,其中没有一个解决了我的问题。下面我将展示我的 View 和 Controller 中的代码,以便您了解我的代码。
View :
<td><% using (Html.BeginForm("Index", "Home", FormMethod.Post, new {enctype = "multipart/form-data"})) { %>
<%: Html.ValidationSummary(true) %>
<div id="section1">
<div class="editor-label">
<%: Html.LabelFor(model => model.Name) %>
</div>
<label for="file">Filename:</label>
<input type="file" name="myfile" id="File5" value="Choose File Banner1" />
<p> </p>
And here is my controller:
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Index(HomeModel model, string submitButton, HttpPostedFileBase myfile)
{
我不知道是什么螨虫的问题..有人可以帮我吗
最佳答案
我也遇到了同样的问题,我在寻找答案时最终来到了这里。我忘记了表单定义中的 enctype 参数
@using (Html.BeginForm("Index", "Home", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
// form
}
关于asp.net-mvc-4 - HttpPostedFileBase 始终保持 null mvc,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19421025/