如何在 ASP.NET MVC 中收集任意长度的列表数据
我需要从 ASP.NET MVC 项目中的用户那里收集与另一个项目关联的项目列表。我想要一个像下面这样的控制器动作。
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Create(int x, int y, IEnumerable<int> zKeys)
{
//Do stuff here
}
如何设置我的表单以这种方式传递数据?如果无法提供这种特定形式的数据,那么在 ASP.NET MVC 中传递此类信息的下一个最佳方法是什么?
I need to gather a list of items associated with another item from my user in a ASP.NET MVC project. I would like to have a controller action like bellow.
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Create(int x, int y, IEnumerable<int> zKeys)
{
//Do stuff here
}
How can I setup my form to pass data in this way? If data of this particular form can't be provided, what's the next best way to pass this type of information in ASP.NET MVC?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Scott Hanselman 有一篇关于如何执行此操作的优秀文章:
ASP.NET Wire Format for Model Binding to Arrays, Lists, Collections, Dictionaries
http://www.hanselman.com/blog/...BindingToArraysListsCollectionsDictionaries.aspx
Scott Hanselman has an excellent article on how to do this here:
ASP.NET Wire Format for Model Binding to Arrays, Lists, Collections, Dictionaries
http://www.hanselman.com/blog/...BindingToArraysListsCollectionsDictionaries.aspx