c# - MVC ActionFilterAttribute 但仅在主视图上

标签 c# asp.net asp.net-mvc actionfilterattribute

我的 Controller 上有一个属性

[ABC]  
MyController

该属性会检查某些内容,但我只想每页检查一次。

public class ABCAttribute : ActionFilterAttribute
{
    public override void OnActionExecuting(ActionExecutingContext filterContext)
    {
        ////Do some check
    }

页面上的每个元素都会触发OnActionExecuting。部分内容等

如何检查filterContext是否是主页而不是页面上的子资源?

最佳答案

public class VerificationAttribute : ActionFilterAttribute
{

    public VerificationAttribute ()
    {
     }

    public override void OnActionExecuting(ActionExecutingContext filterContext)
    {
        //We don't care about children/partials
        if (filterContext.IsChildAction)
            return;


    }

关于c# - MVC ActionFilterAttribute 但仅在主视图上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22413482/

相关文章:

c# - Asp.Net 如何从 jQuery 检索 JSON

c# - vba - 扫描文档中的宏并替换宏文本?

c# - 字典和键值对

c# - 使用文件名从服务器 "programmatically"上的客户端上传文件或 "programmatically"将文件名分配给 UploadFile 控件

c# - 如何获取当前用户,以及如何在 MVC5 中使用 User 类?

c# - DataBinding/WPF C# 的通用 Observable 字典类

c# - parseexact 时,字符串未被识别为有效的 DateTime

asp.net-mvc - 同时使用 AspNet.Identity 和 OpenConnectId(用于 Azure AD 登录)

c# - 模块化网站设计,使用 ASP.NET MVC,我想要一个不那么单一的设计

c# - Windows 身份验证是否使用 aspnet_Users 表?