2

I would like to have the following signature of a MVC controller.

public ActionResult Create(Persons[] p)
{

}

Is it possible to have something like this?

EDIT: Let's say I would like to obtain an array of person objects by submitting a list of names separated by a special symbol. For example I submit a form

<form>
   <input name="person_name">Max|Alex|Andrew</input>
</form>

I suppose it should be done by implementing a IModelBinder interface but I didn't find any example how to do this.

Eugeniu Torica
  • 7,484
  • 12
  • 47
  • 62

4 Answers4

3

Oh I've found how to do this.

In the Global.asax file in the Application_Start() function should be written:

ModelBinders.Binders(typeof(Person[])) = new PersonBinder();

In this manner a custom binder is registered.

Eugeniu Torica
  • 7,484
  • 12
  • 47
  • 62
2

Yes. See this question for how to get collections binded by the DefaultModelBinder.

Community
  • 1
  • 1
Çağdaş Tekin
  • 16,592
  • 4
  • 49
  • 58
0

I think this kind of thing will work

<input type="text" name="Person[1].name" />
Dave Archer
  • 3,022
  • 20
  • 23
0

you may need to play around with a custom controlleractioninvoker.

or just a plain modelbinder

Andrew

Andrew Bullock
  • 36,616
  • 34
  • 155
  • 231