Ola.. I have a problem with editing of few models in table. I have a List of models on page (with foreach), something like
<table id="grid-table" >
@foreach (var image in ViewBag.Images)
{
<tr>
<td >
<a href="@Url.Action("ShowFullImage", new { id = @image.ID })" rel="lightbox[roadtrip]" title="@image.Description" >
<img src="@Url.Action("ShowImageThumbneil", new { id = @image.ID })" alt="@image.AlternateText" />
</a>
</td>
<td >
@using (Html.BeginForm("SaveImageInfo", "Admin", FormMethod.Post))
{
@Html.TextAreaFor(m => m.Description) <br />
@Html.TextBoxFor(m => m.AlternateText) <br />
@Html.LabelFor(m => m.ID)
<div id="item-post" >
<input title="Подтвердить" type="submit" value="Подтвердить" />
</div>
}
</td>
</tr>
}
and I want to have a way to edit ONE model item. In controller I have something like this:
[HttpPost]
public ActionResult SaveImageInfo(ImageModel imageModel)
{
Image img = _core.GetImageByID(_client, imageModel.ID);
img.AlternateText = imageModel.AlternateText;
img.Description = imageModel.Description;
_core.SaveImageInfo(_client, img);
return View();
}
but, of course, it’s not works..
Can somebody help me?
Change
@Html.LabelFor(m => m.ID)with@Html.HiddenFor(m => m.ID). Contents of labels are not sent with POST, but contents of hidden fields are..