asp.net-mvc-4 - HttpPostedFileBase 始终保持 null mvc

标签 asp.net-mvc-4 httppostedfilebase

我知道有很多这样的问题,但我阅读了所有这些问题,其中没有一个解决了我的问题。下面我将展示我的 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>&nbsp;</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/

相关文章:

asp.net-mvc-3 - 将 WebGrease 升级到版本 1.3.0 出现错误

asp.net-mvc-4 - Razor 看不到我的右括号

c# - 将 HttpPostedFileBase 转换到流

asp.net-mvc - System.IO.Stream 支持 HttpPostedFileBase

.net - MVC3 HttpPostedFileBase 第一次上传不提供数据,但随后执行

LINQ 查询具有 2 个集合的对象

asp.net-mvc - 如何将参数传递给 mvc 4 中的局部 View

asp.net-mvc - Paypal 与 MVC 集成,如何将购物车项目详细信息发送到 PayPal

c# - 如何在 View 返回时保留 HttpPostedFileBase