13
shouts

ASP.NET MVC View and Transaction - Kazi Manzur Rashid

published 126 days, 20 hours, 6 minutes ago posted by mithumithu 127 days, 22 hours, 57 minutes ago
Thursday, November 12, 2009 10:15:50 AM GMT Wednesday, November 11, 2009 7:24:45 AM GMT

Scott showed how to render the Grid in a Transaction. Certainly it does the job but in my opinion view component should not be responsible for this kind of cross cutting concerns, instead we can use the Action Filters. Lets see how we can utilize the Action Filter in this scenario instead of modifying the Grid code. What Scott is trying to do is encapsulate the data access operation in a transaction, the Action Filter has several methods which the ASP.NET MVC framework executes in different stages of a request. In this case, we will use the OnActionExecuting which fires before the code enters into the controller method to start a transaction and OnResultExecuted which fires when the view is processed, we will commit/rollback based upon the status, here is the code that would process the action result in a transaction:

category: ASP.NET | clicked: 69 | | source: weblogs.asp.net | show counter code
tags: Action Filter, ASP.NET, ASP.NET MVC, ASPNETMVC, MVC