I have 2 file upload for editing user profile in partial view that called from user profile page. The problem is HttpPostedFileBase
parameter in action method always null
.
When I'm calling this partial view out of profile page and without layout, file uploads was successfully done and sent files to action method.
This is my action method in controller:
[AcceptVerbs(HttpVerbs.Post)]
[Authorize(Roles = "User")]
public ActionResult EditProfile(ProfileGeneralDescription editedModel,
HttpPostedFileBase imageFile,
HttpPostedFileBase coverFile)
{
//Some code here...
}
And this is my partial view cshtml
code:
@model Website.Models.ViewModel.Profile
@using (Ajax.BeginForm("EditProfile", "Profile", new { postOwnerUser = User.Identity.Name }, new AjaxOptions()
{
HttpMethod = "POST",
InsertionMode = InsertionMode.Replace,
UpdateTargetId = "GeneralSection"
}, new { enctype = "multipart/form-data" }))
{
<div>
<button type="submit" name="Save" class="btn btn-default btn-xs">Save Changes</button>
@Ajax.ActionLink("Cancel", "ProfileDescription", "Profile",
new {username = Model.Username, type = "Show"},
new AjaxOptions()
{
HttpMethod = "GET",
InsertionMode = InsertionMode.Replace,
UpdateTargetId = "GeneralSection"
},
new {@class = "btn btn-default btn-xs"})
</div>
<input type="hidden" name="username" id="username" value="@Model.Username"/>
<fieldset>
<legend>Edit Photos</legend>
<div>
Select profile picture:
<input id="imageFile" type="file" name="imageFile" accept="image/png, image/jpeg" />
@Html.CheckBoxFor(modelItem => modelItem.DefaultCover)<span>Remove profile photo</span>
</div>
<div>
Select cover picture:
<input id="coverFile" type="file" name="coverFile" accept="image/png, image/jpeg" />
@Html.CheckBoxFor(modelItem => modelItem.DefaultCover)<span>RemoveCover</span>
</div>
</fieldset>
}
Where is my mistake?
Thanks in advance.