5

I m first time creating a custom action filter and following this link http://www.asp.net/mvc/overview/older-versions/hands-on-labs/aspnet-mvc-4-custom-action-filters

They are saying to Extend ActionFilterAttribute class and also implement IActionFilter interface. ActionFilterAttribute already implement IActionFilter. I m wondering why I need to implement Interface again in my attribute class. Is is something a must to do ? Will highly appreciate if you please can clear this ambiguity.

Robert Harvey
  • 198,589
  • 55
  • 464
  • 673
user576510
  • 211
  • 3
  • 6

2 Answers2

2

You don't need to specify the interface again since the base class already implements it, it is redundant to add it again but it shouldn't harm anything either.

I also don't know why they are explicitly implementing the interface instead of overriding the existing virtual methods which already implement the interface.

Andy
  • 2,003
  • 16
  • 22
2

Or maybe it`s simply a mistake. for instance you can eather inherit from

  1. FilterAttribute, IActionFilter

Or

  1. ActionFilterAttribute

the first one provides low level behavior of MVC Attributes plus Order and AllowMultiple properties.
and the second one provides less details plus OnResultExecutingand OnResultExecuted capabilities.

Rzassar
  • 131
  • 4