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
我们正在使用asp.net mvc-3作为我们的应用程序。我们在控制器的initialize方法中从db填充控制器的属性。我不希望在部分请求和ajax请求上执行此代码。有没有什么方法可以实现这一点而无需直接访问Request对象?任何改变方法的建议也是受欢迎的
1 个解决方案
#1
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.
如果可用,为什么不使用Request.IsAjaxRequest?如果您不想要此属性,则需要访问请求对象中的标头。部分请求无论如何都不会打到你的控制器 - 只有RenderAction会命中你的控制器。 RenderPartial只会点击您的视图。
#1
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.
如果可用,为什么不使用Request.IsAjaxRequest?如果您不想要此属性,则需要访问请求对象中的标头。部分请求无论如何都不会打到你的控制器 - 只有RenderAction会命中你的控制器。 RenderPartial只会点击您的视图。