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 の値を確認すると、値は null でした。その理由は何でしょうか?ありがとう

4

1 に答える 1