0

朋友们..我还有一个麻烦。可能很愚蠢,但我看不出,有什么问题。

    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。但。我有这个: 在运行时观看 这是我的问题:为什么?我看不到...

4

1 回答 1

2

在我看来,您需要在视图中为 GalleryId 添加一个 HiddenFor:

@Html.HiddenFor(m => m.GalleryId)

于 2012-10-17T16:15:10.153 回答