吾友.. 我还有一个麻烦。 愚蠢可能,但我看不出,有什么不对。
public ActionResult Images(Guid? id)
{
ViewBag.Gallery = _core.GetGalleryByID(_client, (Guid)id);
List<ImageModel> models = new List<ImageModel>();
foreach (var img in _core.GetImagesByGalleryID(_client, (Guid)id))
{
ImageModel model = new ImageModel(_client);
model.Thumbneil = img.Thumbneil;
model.Description = img.Description;
model.AlternateText = img.AlternateText;
model.GalleryID = img.GalleryID;
model.ID = img.ID;
models.Add(model);
}
ViewBag.Images = models;
return View();
}
[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();
}
这是控制器的一部分。 这是观点的一部分:
@model WebUI.Models.ImageModel
@{
ViewBag.Title = "Images";
Layout = "~/Views/Admin/_Layout.cshtml";
}
<h2>@ViewBag.Gallery.Name</h2>
<table id="grid-table" >
@foreach (var image in ViewBag.Images)
{
<tr>
....
<td >
@using(Html.BeginForm("SaveImageInfo", "Admin", FormMethod.Post))
{
@Html.HiddenFor(m => m.ID)
@Html.TextAreaFor(m => m.Description) <br />
@Html.TextBoxFor(m => m.AlternateText) <br />
<div id="item-post" >
<input title="Подтвердить" type="submit" value="Подтвердить" />
</div>
}
</td>
</tr>
}
</table>
模特:
public class ImageModel
{
public Byte[] Thumbneil { get; set; }
[Required]
public String Description { get; set; }
[Required]
public Guid GalleryID { get; set; }
[Required]
public String AlternateText { get; set; }
[Required]
public Guid ID { get; set; }
}
在ActionResult中,SaveImageInfo(ImageModel imageModel)我应该有2个Guid:ID和GalleryID。但。
我有这个:
这是我的问题:为什么?我看不到......
答案 0 :(得分:2)
在我看来,你需要在视图中为GalleryId添加一个HiddenFor:
@ Html.HiddenFor(m =&gt; m.GalleryId)