0

我很好奇,而不是使用 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 的值时,该值为空。这可能是什么原因?谢谢

4

1 回答 1

1

您使用了错误的课程。您的财产需要HttpPostedFileBase

public class UserLoginModel
{
    ....
    public HttpPostedFileBase Resume { get; set; }
}
于 2015-11-27T02:56:12.540 回答