Czy dobrze rozumiem aby przekazać Id usera któremu zmieniam avatara muszę stworzyć
HiddenFor(x=>x.Id)
aby przekazć do akcji
ChangeAvatar(string userId)
Wygląda to tak:
[HttpPost]
public ActionResult ChangeAvatar(HttpPostedFileBase file, string Id)
{
userService.ChangeAvatars(file, Id);
return RedirectToAction("Index", "Home");
}
@model Shop.Models.ApplicationUser
@{
ViewBag.Title = "ChangeAvatar";
}
<h2>Zmiania Avatara</h2>
<div>
@using (Html.BeginForm("ChangeAvatar", "Manage", FormMethod.Post ,new { enctype = "multipart/form-data" }))
{
@Html.AntiForgeryToken()
<hr />
@Html.ValidationSummary("", new { @class = "text-danger" })
@Html.HiddenFor(x=>x.Id)
<div class="form-group">
@Html.LabelFor(m => m.ImageUrl, new { @class = "col-md-2 control-label" })
<div class="col-md-10">
<input type="file" name="file" id="file" />
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Zmień Avatar" class="btn btn-default" />
</div>
</div>
}
</div>
a kod html wygenerował się tak
<input name="__RequestVerificationToken" type="hidden"
value="lPFovpod3niOuKqMQc5sYtvP1mJIbFhGy84HHLrteQkFV6tjuMx0W0DSzW8-2PGLdewMzaR71ORyup6ABmRzNKAm4CfkX2cCjQXh2fECe3BC9B-cA6yCxkupWT4YtfnjYnWOZlaZOLb_Zo8VKjdmYA2">