2013-02-14 43 views
0

我有一个表单应该接受用户的凭证和他的简历。 PDF/DOC仅上传word/pdf文件并通过ASP.NET MVC中的模型将链接存储在数据库中MVC

我已经在那里我打算在服务器路径存储上传的文件作为一个字符串

我产生一个强类型的观点,即通过

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

取文件在数据库我在模型中创建了一个HttpPostedFileBase对象。而model.file应该存储HttpPostedFileBase文件对象。

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

我在做什么错。为什么模型绑定没有绑定文件上传?

回答

4

添加enctype="multipart/form-data"形成选项

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

} 
相关问题