This project is read-only.

Creating a custom criteria (ASP.NET MVC 3)

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
{
    #region Fields

    private readonly string _actionName;

    #endregion

    #region Constructor

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

    #endregion

    #region Implementation of IActionFilterCriteria

    public bool Match(ControllerContext controllerContext, ActionDescriptor actionDescriptor)
    {
        return string.Equals(_actionName, controllerContext.RouteData.GetRequiredString("action"), StringComparison.OrdinalIgnoreCase);
    }

    #endregion
}

Last edited Feb 9, 2011 at 12:29 AM by banguit, version 4

Comments

No comments yet.