加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net-mvc-4 – HttpPostedFileBase始终保持为空mvc

发布时间:2020-12-16 07:29:05 所属栏目:asp.Net 来源:网络整理
导读:我知道有很多像这样的问题,但是我把它们全部读出来并且它们无效解决了我的问题.下面我将展示我在视图和控制器中的代码,以便您可以了解我的代码. View :td% using (Html.BeginForm("Index","Home",FormMethod.Post,new {enctype = "multipart/form-data"})) {
我知道有很多像这样的问题,但是我把它们全部读出来并且它们无效解决了我的问题.下面我将展示我在视图和控制器中的代码,以便您可以了解我的代码.

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",new { enctype = "multipart/form-data" }))
{
// form
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读