In a ASP.NET MVC (4) application, I am using a 3rd party Javascript library that auto-magically sends back a query string parameter with a poor name (IMO). I can intercept this value in model binding with the following:
public ActionResult MyAction([Bind(Prefix="rp")] int pageSize = 50)
{
}
However, this code inside all the places where I use paging gets tiresome pretty quickly.
Is it possible inside ASP.NET MVC to globally set a [BindAttribute] with a specific prefix/replacement combination?
A workaround would be to modify the Javascript library (undesirable); or get the parameter out of the Request.QueryString property manually; but I was hoping to keep things cleaner.
You could use a view model:
in your controller action(s):
and then write a custom model binder for this view model:
that will be registered in
Application_Start: