we are using asp.net mvc-3 for our application. we populate a property of controller from db on initialize method of controller. i don't want this code to be executed on partial requests and ajax requests. is there some way i can achieve this without directly accessing Request object? Any suggestions in change of approach are also welcome
Asked
Active
Viewed 98 times
1 Answers
1
Why not use the Request.IsAjaxRequest if its available? If you don't want this property you need to access a header, which is in the request object anyways. The partial request won't hit your controller anyways - only RenderAction will hit your controller. RenderPartial will only hit your view.

Adam Tuliper
- 29,982
- 4
- 53
- 71
-
how would i test if i used Request object directly in my controller – Muhammad Adeel Zahid May 09 '11 at 17:38
-
Mock httpcontext - depends on what mock framework you use but: http://stackoverflow.com/questions/1452418/how-do-i-mock-the-httpcontext-in-asp-net-mvc-using-moq (various methods on there) – Adam Tuliper May 10 '11 at 02:30