【问题标题】:Custom Attribute class not getting called?自定义属性类没有被调用?
【发布时间】:2018-01-20 14:45:17
【问题描述】:

我创建了一个属性类,这里是代码

    namespace ZDemo.Validate1
{
    public class ValidateRequest : ActionFilterAttribute
    {

        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
           /*further code*/
            }
        base.OnActionExecuting(filterContext);
    }
}

}

并将其作为属性添加到不同控制器中的某些操作

  [Validate1.ValidateRequest]
    public ActionResult Add()
    {
        return View();
    }

但是当我用调试器运行这段代码时,它根本没有被调用。 我做错了什么?

【问题讨论】:

  • 您的代码中似乎存在复制/粘贴错误?您在 OnActionExecuting 方法之外显示 base.OnActionExecuting。那不会编译。

标签: asp.net-mvc attributes


【解决方案1】:

在方法开头调用base.OnActionExecuting(filterContext);

public override void OnActionExecuting(ActionExecutingContext filterContext)
{
    base.OnActionExecuting(filterContext);

    //Your code here
}

【讨论】:

  • 谢谢,如果你也提供原因就好了?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-11-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-10-15
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多