Strongly-Typed ASP.NET MVC with Entity Framework

后端 未结 5 549
孤街浪徒
孤街浪徒 2020-12-16 09:01

This code fails to actually save any changes:

//
// POST: /SomeType/Edit/5

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Edit(Guid id, SomeType Model)
{         


        
5条回答
  •  没有蜡笔的小新
    2020-12-16 09:22

    What happens if you add one line:

    [AcceptVerbs(HttpVerbs.Post)]
    public ActionResult Edit(Guid id, SomeType Model)
    {
        db.AttachTo(Model.GetType().Name, Model);
        Model.SomeProperty = Model.SomeProperty; // This looks hacky... =(
        db.ApplyPropertyChanges(Model.EntityKey.EntitySetName, Model);
        db.SaveChanges();
        return RedirectToAction("Index");
    }
    

    Does the state change?

提交回复
热议问题