0

使用 DynaamicData,我有一个标准的多对多表,在插入新的唯一行时工作得非常好。两个父表的下拉列表都按原样显示,并且该行被正确插入。

但是,在一张桌子上,我有一个唯一索引,它会引发一个异常,我可以在 OnInserted 事件处理程序中捕获该异常。然后,我可以向用户发回一条友好的消息,告知他们问题所在。出现此问题的原因是 DetailsView 丢失了视图状态,并且用户为 DropDownLists 选择的值被重置为页面的默认值。

protected void DetailsDataSource_Inserted(object sender, LinqDataSourceStatusEventArgs e)
{
    if (e.Exception != null && !e.ExceptionHandled)
    {
        msgPanel.Text = "Error Occurred"; // or some other friendly message
        e.ExceptionHandled = true;

        // e.Result == null, so I can't rebuild the user's input from here.
        // What can be put where to get the user's input restored?
    }
}
4

1 回答 1

0

我倾向于将错误包装在模型中的验证异常中,这会导致验证错误,并且应该使您的用户输入保持不变。

史蒂夫

于 2010-12-12T11:28:16.840 回答