ASP.NET MVC模型绑定。呼叫控制器对象参数数组 [英] ASP.NET MVC Model Binders. Call a controller with an array of objects parameter
问题描述
我想有一个MVC控制器的以下签名。
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?
编辑:
比方说,我想通过提交一个特殊的符号分隔的名称列表,以获得人对象的数组。
比如我提交表单
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>
我想它应该通过实现IModelBinder界面来完成,但我没有找到任何例子,如何做到这一点。
I suppose it should be done by implementing a IModelBinder interface but I didn't find any example how to do this.
推荐答案
哦,我已经找到了如何做到这一点。
Oh I've found how to do this.
在在Application_Start Global.asax文件()函数应该写成:
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.
这篇关于ASP.NET MVC模型绑定。呼叫控制器对象参数数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!