0

我有一个用于生成列表的 ViewData,在选择一个项目后,项目信息将显示在文本框中以供查看和编辑。单击保存按钮后,它会保存但列表框未更新,由于我使用的是视图数据,如何更新此列表框?

   @Html.ListBox("ListBoxName", new SelectList((IEnumerable<Epic>)ViewData["selectedestimate"], "Id", "Name", "EstimatedTime"), new {@class = "ListBoxClass", @style = "height: 325px;"})

   <button id="EpicSaveId" type="submit" class="btn" onclick="SaveEpicInfo((document.getElementById('EpicNameID').value), (document.getElementById('EpicTimeId').value), (document.getElementById('EpicDescriptionID').value))">

单击保存按钮后:(Javascript)

        function SaveEpicInfo(name, time, description) {
    $.get('@Url.Action("SaveEditEpic", "Estimate")', { id: eid, epicname: name, epictime: time, epicdescription: description }, function (result) {
        alert(result);

    });

}

控制器:

     [AcceptVerbs(HttpVerbs.Get)]
    public JsonResult SaveEditEpic(int id, string epicname, double epictime, string epicdescription)
    {
        var epic = epicRepository.Select().SingleOrDefault(x => x.Id.Equals(id));
        if (epic != null)
        {
            epic.Name = epicname;
            epic.EstimatedTime = epictime;
            epic.EpicDescription = epicdescription;
            //ViewData["selectedestimate"] = epicRepository.Select().Where(x => x.EstimateId.Equals(ActiveEstimateId)).ToList();
            return Json("Epic Saved", JsonRequestBehavior.AllowGet);
        }
        else
        {
            return Json("Error");
        }
    }
4

1 回答 1

1

您将不得不遍历这些选择数组并查找带有 selected = true 的选项,然后存储该值。

于 2012-04-16T00:51:18.410 回答