传递给 delete 方法的项目不会完全删除

Item passed into the delete method don't delete completely

在我的项目中,当我想删除一个新闻组时,它没有删除。

这是“删除”方法体:

enter code public bool DeleteGroup(PageGroup pageGroup)
    {
        try
        {
            db.Entry(pageGroup).State=EntityState.Deleted;
         
            return true;
        }
        catch (Exception)
        {

            return false;
        }
    }

这将从控制器调用 Delete 方法:

   @Html.ActionLink("Delete", "Delete", new { id = item.GroupID })

这是控制器中的删除操作:

 public ActionResult Delete(int? id)
    {
        if (id == null)
        {
            return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
        }
       PageGroup pageGroup = PageGroupRepository.GetGroupById(id.Value);
        PageGroupRepository.DeleteGroup(pageGroup);
     
        if (pageGroup == null)
        {
            return HttpNotFound();
        }
        return View(pageGroup);
    }

这是删除按钮:

 @using (Html.BeginForm()) {
    @Html.AntiForgeryToken()

    <div class="form-actions no-color">
        <input type="submit"  value="Delete" class="btn btn-default" /> |
        @Html.ActionLink("Back to List", "Index")
    </div>

问题出在哪里?删除按钮还是删除方法?

您删除后忘记保存更改:

public bool DeleteGroup(PageGroup pageGroup)
    {
        try
        {
            db.Entry(pageGroup).State=EntityState.Deleted;
            db.SaveChanges();
            return true;
        }
        catch (Exception)
        {

            return false;
        }
    }