0

我遇到了一个问题,即选择、编辑列表对象,然后将其重定向回列表,但该对象未显示它已在列表中更新。如果选择了已编辑对象的详细信息视图,则已保存对对象的编辑。我需要该列表来更新所做的更改。

这是为“索引”视图生成列表的方法:

public static List<MortgageCancellation> DealerSorting(string id,string dealerId)
    {
        var d = from u in db.MortgageCancellations
                where u.DealerID == dealerId
                select u;
        switch (id)
        {
            case "DealID":
                return d.OrderBy(u => u.DealID).ToList();
            case "PrimaryFirstName":
                return d.OrderBy(u => u.PrimaryFirstName).ToList();
            case "PrimaryLastName":
                return d.OrderBy(u => u.PrimaryLastName).ToList();
            case "DateOfApplication":
                return d.OrderBy(u => u.DateOfApplication).ToList();
            case "ProfileStatus":
                return d.OrderBy(u => u.ProfileStatus).ToList();
            case "CurrentStep":
                return d.OrderByDescending(u => u.CurrentStep).ToList();
            case "LastUpdated":
                return d.OrderByDescending(u => u.LastUpdated).ToList();
            default:
                return d.ToList();
        }
    }

这是进行编辑的地方,您可以看到它保存了更改:

public ActionResult Edit(MortgageCancellation mortgagecancellation)
    {
        try
        {
            if (ModelState.IsValid)
            {
                mortgagecancellation.DateOfApplication = (DateTime?)Session["appDate"];
                Session.Remove("appDate");
                mortgagecancellation.LastUpdated = DateTime.Now;
                db.Entry(mortgagecancellation).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            return View(mortgagecancellation);
        }
        catch (Exception ex)
        {
            SupportEmail se = new SupportEmail(error, ex);
            SupportEmail.SendSupportEmail(se);
            return View("Error");
        }
    }

我不确定为什么“索引”视图没有显示所做的更改,因为这是从“索引”视图调用的唯一方法:

return View(MortgageCancellation.OfficeSorting(id));

还有一件事,列表最终会显示更改,但我需要列表立即显示更改。

这是数据库初始化的地方:

private static MyDBContext db = new MyDBContext();
4

1 回答 1

1

尝试更换

private static MyDBContext db = new MyDBContext();

using(var db = new MyDBContext())
{
    ...code..
}

对于每个动作。

于 2012-09-21T22:41:25.877 回答