This project is read-only.

Creating a custom criteria (ASP.NET MVC 2)

To create a custom criteria you should inherit your class from IFilterCriteria interface and implement only one method Match.

Example of criteria:
public class ActionFilterCriteria : IFilterCriteria
    private readonly string _actionName;

    /// <summary>
    /// Filter by specified action
    /// </summary>
    /// <param name="actionName">Name of the action</param>
    public ActionFilterCriteria(string actionName)
        _actionName = actionName;

    #region Implementation of IActionFilterCriteria

    public bool Match(FilterRegistryContext context)
        return string.Equals(_actionName, context.ControllerContext.RouteData.GetRequiredString("action"), StringComparison.OrdinalIgnoreCase);


Last edited Jan 30, 2011 at 9:21 PM by banguit, version 5


No comments yet.