I'm curious instead of using HTTPFileWrapper, i created a model with HttpFileCollectionBase type of property.
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; }
}
My View
@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>
}
And my Controller for postback
[HttpPost]
public ActionResult Index(UserLoginModel obj)
but when I checked the value of model.Resume on the controller the value was null. what could be the reason for that? thanks
You using the wrong class. Your property needs to be
HttpPostedFileBase