Pass array of integers to Get / ASP.NET Web API -


i know how pass arrays function this: /?index=1&index=5&index=3

but need able receive arrays this: /?index=[1,5,3]

or short. there can use?

use custom modelbinder:

public class jsarraystylemodelbinder : defaultmodelbinder {     public override object bindmodel(controllercontext controllercontext, modelbindingcontext bindingcontext)     {         var value = bindingcontext.valueprovider.getvalue(bindingcontext.modelname);          if (value == null)             return null;          return new javascriptserializer().deserialize<string[]>(value.attemptedvalue);     } } 

then register in global.asax:

modelbinders.binders.add(typeof(string[]), new jsarraystylemodelbinder()); 

or directly on action parameter:

[httpget] public actionresult show([modelbinder(typeof(jsarraystylemodelbinder))] string[] indexes) 

Comments

Popular posts from this blog

How to mention the localhost in android -

php - Calling a template part from a post -

c# - String.format() DateTime With Arabic culture -