Search code examples
c#asp.netasp.net-mvcaction-filtercustom-action-filter

Action filter attribute


Is it possible to have a ActionFilterAttribute parameters like this ?

[DataType(DataType.Password)]

For example I need to create something like this

[ValidateSession(Session.Required)]

public class ValidateSession : ActionFilterAttribute
{
    enum Session
    {
        Required,
        NotRequired
    }

    private Session _session { get; set; }

    public ValidateSession(Session session)
    {
        this._session = session;
    }
}

Solution

  • You can add parameters to custom ActionFilter. For more information see this.