not sure if this is possible or if i am down the wrong road.
i am wanting to use an attribute to clean out single quotes from my form posted data
(this will be changed, but single quotes is a good example)
i have created the actionFilter as below:
public class RemoveSingleQuotesAttribute : ActionFilterAttribute
{
public NameValueCollection collection { get; set; }
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
for (int i = 0; i < collection.Count; i++)
{
collection.Set(
collection.GetKey(i),
collection.GetValues(i).ToString().Replace("'","`")
);
}
}
}
now this is where i get stuck:
when i type [RemoveSingleQuotes()] in brackets i only get [Int Order] as the intelisense
and not formcollection/Namevaluecollection
and also how do i pass a collection anyway ?????
is this even possible or am i just creating some mad sh*t up here ????
thanks
You can access formvalues in the filter by filterContext.RequestContext.HttpContext.Request.Form. Anyway it would be easier to build a custom modelbinder that strips of unwanted characters.
That way you can still work with the a bound Model. Your solution will lead to a changed Formcollection, but an unchanged Model. You could call UpdateModel after your changes, but it is still is not a good solution.
EDIT
EDIT 1
I would apply the ModelBinder this way: