Asp.net mvc equivalent of rails before_save callback

Hi I am looking for an asp.net mvc callback to design data before saving the model.

There is a before_save in rails.

thanks

+2


a source to share


1 answer


If you are using Entity Framework (which your tag points to) then fooobar.com/questions/1701796 / ... should help you. Basically you can intercept the SavingChanges event and do whatever you want. Put this in a partial class that adds the following methods to the context of your object:



partial void OnContextCreated()
{
    SavingChanges += DoWhatYouMust;
}

private void DoWhatYouMust(object sender, System.EventArgs e)
{
}

      

+3


a source







All Articles