0

我在网格中更新项目后调用了方法:

public void GridView1_UpdateItem(int noteId)
{
    Notes itemToEdit = context.Notes.FirstOrDefault(x => x.NoteId == noteId);
    Notes originalItem = context.Notes.FirstOrDefault(x => x.NoteId == noteId);

    TryUpdateModel(itemToEdit); //it should update only object itemToEdit
}

为什么TryUpdateModel(itemToEdit)还要更新对象 originalItem?对象 originalItem 具有来自表单的新值,但它应该具有旧值。

4

1 回答 1

0

您的更新功能正在获取旧值可能是您没有使用Page.IsPostBack属性Page_Load的原因

protected void Page_Load(object sender, EventArgs e)
    {

        if (!Page.IsPostBack)
        {
        // Your code..
        }
    }
于 2013-06-12T05:12:23.003 回答