确定请求是ASP.NET MVC 3中的PartialView还是AJAX请求 [英] Determine if request is PartialView or AJAX request in ASP.NET MVC 3

查看:80
本文介绍了确定请求是ASP.NET MVC 3中的PartialView还是AJAX请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须赋予网站用户访问权限. 我在这里进行过滤:

I have to give access rigths to the users of a website. I am doing the filtering here:

protected override void OnActionExecuting(ActionExecutingContext filterContext)
{
}

问题是我无法将完整的View请求(例如索引")与PartialViewRequests或AJAX调用请求区分开来.

The problem is that I cannot distinguish full View request such as 'Index' from PartialViewRequests or AJAX calls requests.

因此,页面'Index'可以访问,但'PartialViewGridViewForIndex'没有访问权限.

Therefore the page 'Index' has access but the 'PartialViewGridViewForIndex' does not have access.

属性ControllerContext.IsChildAction也不起作用.

推荐答案

您可以使用

You could use the IsAjaxRequest extension method to determine if an AJAX request was used to invoke this controller action:

protected override void OnActionExecuting(ActionExecutingContext filterContext)
{
    if (filterContext.HttpContext.Request.IsAjaxRequest())
    {
        // the controller action was invoked with an AJAX request
    }
}

这篇关于确定请求是ASP.NET MVC 3中的PartialView还是AJAX请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆