i\'hv written my own action filter and registered in global.asax file, now my problem is how do i skip this filter for specific actions, i thought about this by creating a custo
You could get the list of attributes that were used to decorate the controller action from the ActionDescriptor
property of the context:
public class ValidationActionFilter : ActionFilterAttribute
{
public override void OnActionExecuting(HttpActionContext context)
{
if (context.ActionDescriptor.GetCustomAttributes().Any())
{
// The controller action is decorated with the [DontValidate]
// custom attribute => don't do anything.
return;
}
if (context.Request.Method.ToString() == "OPTIONS") return;
var modelState = context.ModelState;
if (!modelState.IsValid)
{
JsonValue errors = new JsonObject();
foreach (var key in modelState.Keys)
{
// some stuff
}
context.Response = context.Request.CreateResponse(HttpStatusCode.BadRequest, errors);
}
}
}