Kirill A.
Kirill A.

Reputation: 1815

inline models editor MVC3. Again

amigos.. I have one more trouble. Stupid may be, but I can't see, what's wrong.

    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();
    }

This is part of controller. This is part of 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>

And model:

    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; }
}

In ActionResult SaveImageInfo(ImageModel imageModel) I should have 2 Guids: ID and GalleryID. BUT. I have this: watch at run time And this is my question: WHY? I can't see...

Upvotes: 0

Views: 90

Answers (1)

ledragon
ledragon

Reputation: 301

Looks to me like you need to add a HiddenFor for GalleryId in the view:

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

Upvotes: 2

Related Questions