简体   繁体   English

如何在MVC中将可变大小的数据结构从视图传递回控制器?

[英]How do I pass a variable size data structure back to the controller from my view in MVC?

I'm creating a view based on a list, intending to allow users to edit one or more members of the list, at the same time, on the same page. 我正在基于列表创建视图,旨在允许用户在同一页面上同时编辑列表的一个或多个成员。

I'd like to collect all of the edited (or, failing that, all) fields into a data-structure (a list or array?) to pass back to the controller, who will then update my database, as appropriate, for each element in the list. 我想将所有已编辑(或失败的所有)字段收集到数据结构(列表或数组?)中,以传递回控制器,然后控制器将根据需要为每个数据库更新我的数据库列表中的元素。

Is there an MVC .NET shorthand for building this type of view, or do I have to manually collect this data on the client side (say, with Javascript) before passing it back to the server? 是否有用于构建这种视图的MVC .NET速记,还是在将其传递回服务器之前必须在客户端(例如,使用Javascript)手动收集此数据?

You may take a look at the following blog post . 您可以查看以下博客文章 Also checkout the following post to better understand the expected wire format for lists and dictionaries used by the default model binder in ASP.NET MVC. 另外,请查看以下文章,以更好地了解ASP.NET MVC中默认模型绑定程序使用的列表和字典的预期连线格式。

There are a few elements to this problem: 此问题有几个要素:

  1. Creating a view that will allow you to add/edit multiple items . 创建一个允许添加/编辑多个项目的视图。
  2. Sending that information back to the controller. 将该信息发送回控制器。 Reading up on Modelbinding to a list will solve the second part. 阅读Modelbinding到列表将解决第二部分。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将对象从我的视图传递到 ASP.NET MVC 中的控制器? - How can I pass an object from my view to my controller in ASP.NET MVC? MVC从控制器传递ICollection以查看并返回控制器而不显示它 - MVC pass ICollection from controller to view and back to controller without displaying it MVC 4 如何正确地将数据从控制器传递到视图 - MVC 4 how pass data correctly from controller to view 将对象数据从控制器传递到MVC C#中的部分视图 - Pass object data from controller to Partial View in MVC C# ASP.NET MVC:将复杂的数据从视图传递到控制器 - ASP.NET MVC: Pass complex data from View to Controller .NET MVC:将复杂对象或列表数组从视图传递回控制器 - .NET MVC : Pass back complex object or list array from view to controller 如何使用Html.ActionLink将文本框(DatePicker)变量传递给控制器​​? - How do I pass a textbox (DatePicker) variable to my controller using Html.ActionLink? MVC4-如何将IPagedList模型传递给控制器 - MVC4 - How do I pass IPagedList model to controller ASP.NET MVC5:如何将数据传递到视图? - ASP.NET MVC5 : How do I pass data to a view? ASP.NET 核心 MVC - 将 Model 数据从视图传递回 Controller - ASP.NET Core MVC - Passing Model Data Back to Controller from View
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM