HttpFileCollectionBase 的值在回发时为空

Value of HttpFileCollectionBase Isnull on Postback

我很好奇,我没有使用 HTTPFileWrapper,而是创建了一个 HttpFileCollectionBase 类型为 属性 的模型。

public class UserLoginModel
{
[Required]
[Display(Name = "User name")]
public string UserName { get; set; }

[Required]
[DataType(DataType.Password)]
[Display(Name = "password")]
public string Password { get; set; }


public HttpFileCollectionBase Resume { get; set; }

}

我的观点

@using (Html.BeginForm("", "User", FormMethod.Post, new { enctype = "multipart/form-data", @class = "form-horizontal" }))
{
   //  @Html.AntiForgeryToken()
<table>
    <tr>
        <td>
            @Html.LabelFor(x => x.UserName)
        </td>
        <td>
            @Html.EditorFor(x => x.UserName)
        </td>
    </tr>
    <tr>
        <td>
            @Html.LabelFor(x => x.Password)
        </td>
        <td>
            @Html.EditorFor(x => x.Password)
        </td>
    </tr>
    <tr>
        <td colspan="2">
            <input type="submit" value="login" onclick="return Upload();">
        </td>
    </tr>
    <tr>
        <td colspan="2">
            @Html.TextBoxFor(x => x.Resume, new { type = "file" })
        </td>
    </tr>
    <tr>
        <td colspan="2">
            @Html.ValidationSummary(true)
        </td>
    </tr>
</table>
}

还有我的回发控制器

    [HttpPost]
    public ActionResult Index(UserLoginModel obj)

但是当我在控制器上检查 model.Resume 的值时,该值为空。可能是什么原因呢?谢谢

你用错了class。您的 属性 需要 HttpPostedFileBase

public class UserLoginModel
{
    ....
    public HttpPostedFileBase Resume { get; set; }
}