【问题标题】:Uploading word/pdf file only and storing the link on a database through a model in ASP.NET MVC仅上传 word/pdf 文件并通过 ASP.NET MVC 中的模型将链接存储在数据库中
【发布时间】:2013-02-14 12:51:28
【问题描述】:

我有一个表单,它应该包含用户的凭据和他的简历。 PDF/文档

我已经有一个数据库,我计划将上传文件的服务器路径存储为字符串

我生成了一个强类型视图,通过

接收文件
<%: Html.EditorFor(model => model.file, new { type = "file" })%>

我在模型中创建了一个 HttpPostedFileBase 对象。并且model.file应该存储HttpPostedFileBase文件对象。

但在控制器中,当我尝试获取 model.file 对象时,我得到 null 作为它的值。

我做错了什么。为什么模型绑定不绑定文件上传?

【问题讨论】:

    标签: asp.net-mvc file-upload web model-binding


    【解决方案1】:

    在表单选项中添加enctype="multipart/form-data"

    @using (Html.BeginForm("Action", 
        "Controller", 
        FormMethod.Post, 
        new 
        { 
            id = "form", enctype="multipart/form-data" 
        }))
    {
    
    }
    

    【讨论】:

      猜你喜欢
      • 2021-04-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-15
      • 2011-05-08
      • 2020-08-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多