Reputation: 15378
I have class:
EmployeeListViewModel
with property List<Int32> EmployeeIDs
.
I need transfer with get request.
I do not want to see a request like EmployeeIDs[]=1&EmployeeIDs[]=2
...
I want to specify a tag which has a short name of this parameter
example:
empl[]=1&empl[]=2
Upvotes: 1
Views: 91
Reputation: 27343
Sounds like you're using Model Binding and want to customize the way binding happens. Unfortunately, on a Model
class, I don't know of a way to use attributes to accomplish this, but you can accomplish what you want using a custom binder.
You'll need to implement the IModelBinder
interface, and then use a [ModelBinder]
attribute on your Controller's action method.
More details here: http://dotnetslackers.com/articles/aspnet/Understanding-ASP-NET-MVC-Model-Binding.aspx
Upvotes: 0
Reputation: 1038750
You could decorate the controller action argument with the [Bind]
attribute and specify a prefix:
public ActionResult Index([Bind(Prefix = "empl[]")] int[] employeeIDs)
{
...
}
Now the following request will be correctly bound:
empl[]=1&empl[]=2
Upvotes: 1