开发者

with mvc.net is there an event that is raised after the view is rendered

开发者 https://www.devze.com 2023-01-30 13:15 出处:网络
I am portin开发者_如何学Gog an asp.net webforms application to mvc.net.I have an OR framework that requires a DataSession object to be created before any database operations can be performed.

I am portin开发者_如何学Gog an asp.net webforms application to mvc.net. I have an OR framework that requires a DataSession object to be created before any database operations can be performed.

In my current webform application I instantiate the DataSession during the Page_Init event and during the Page_UnLoad event I clear the object.

I am looking for something similar with mvc.net. I have initially started with using the OnACtionExecuting (raised before an action) and OnActionExecuted (raised after the action). However, during the rendering of the page there is some lazy loading of entities that fail as the DataSession is no longer available. What I need is something that will fire after the View has been rendered.


You shouldn't let lazy loading occur in your view pages. That means the view accesses data which breaks the entire point of MVC.

Instead you should get the entirety of the data in your controller and then pass that to your view.


Load the db connection in OnActionExecuting and unload in OnResultExecuted.

Although I would use Application_BeginRequest and Application_EndRequest in global.asax.


I haven't used these methods before, but perhaps look into overriding OnResultExecuted or OnResultExecuting.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号