asp.net mvc等同于rails回调before_save [英] asp.net mvc equivalent of rails callback before_save
问题描述
在rails中有一个before_save。
谢谢
如果您正在使用Entity Framework(您的标签表示)一个href =https://stackoverflow.com/questions/450601/intercept-entity-saving-with-ado-net-net-entities-framework>这个StackOverflow文章应该能够帮助你。基本上你可以拦截SavingChanges事件,并且做任何你想要的。将它放在一个部分类中,将以下方法添加到对象上下文中:
partial void OnContextCreated()
{
SavingChanges + = DoWhatYouMust;
}
private void DoWhatYouMust(object sender,System.EventArgs e)
{
}
Hi i'm looking for a asp.net mvc callback for elaborate data before save a model.
In rails there is before_save.
Thanks
If you are using Entity Framework (which your tag indicates), then this StackOverflow post should be able to help you out. Basically you can intercept the SavingChanges event, and do whatever you want. Put this in a partial class that adds the following methods to your object context:
partial void OnContextCreated()
{
SavingChanges += DoWhatYouMust;
}
private void DoWhatYouMust(object sender, System.EventArgs e)
{
}
这篇关于asp.net mvc等同于rails回调before_save的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!